Skip to main content
Documentation/Dynamic Data/Conditions/Custom PHP Conditions

Custom PHP Conditions

Custom PHP conditions use your PHP code to decide whether an element displays or a template applies.

Adding a Custom PHP Condition

  1. Open the element’s or template’s conditions and click Add Condition.
  2. Choose Custom PHP from the Other group, then click Open PHP Editor.
  3. Enter PHP that returns true when the condition should pass or false when it should fail. Omit PHP tags and a wrapping function.
  4. Apply the conditions and save your changes.
The PHP Editor dialog for a Custom PHP condition
The PHP Editor dialog for a Custom PHP condition

For example, this condition passes when the current post has the featured tag:

PHP
global $post;
if ($post && has_term('featured', 'post_tag', $post)) {
    return true;
}
return false;

To register a reusable named condition, see the Conditions API.