There are a number of ways to echo PHP 'If' a statement is true. The most common syntax is:-

The example will output if the current time (HOUR) is less than 12.

Echo HTML or PHP in PHP If Statement

We also like to use an alternate echo that allows you to inject PHP or HTML within the If Statement and this is useful in writing more complicated scripts. So something like:-

Show and trim the WordPress excerpt if Statement value is true

With these basic building blocks you can advance the above snippet to something like:-

The script does the following:-

  1. Looks for a 'true' value (as opposed to 'false')
  2. Gathers the excerpt from the WordPress Post (custom posts etc)
  3. Trims the excerpt by a length specified by our '$my_excerpt_length' (you can also use a numerical value here) and adds the permalink to the WordPress Post
  4. Echoes the trimmed excerpt

We hope you find this useful.