Skip to content

Conditional Logic

In this article

    Total includes a Conditional Logic feature that lets you control when certain functionality is enabled or disabled, based on a conditional string. Two examples of the Conditional Logic function can be found in the Transparent Header and Primary Bottom Spacing options in the Customizer.

    Here is an example of a Conditional Logic field:

    A Conditional Logic field takes a string of conditional functions (e.g., is_singular, is_home, is_user_logged_in) and evaluates them in the current request context.

    Using a Conditional Logic Field

    You can define conditions using a simple query style string:

    • Use a query string format: function_name=parameter
    • Use multiple conditions separated by &.
    • Parameters for functions that accept arrays can be comma-separated (e.g., is_singular=post,portfolio).
    • You can negate conditions by prefixing them with ! to exclude specific cases (e.g., !is_page=about).

    This flexible format lets you combine multiple conditions with OR logic, enabling functionality when any condition is true, while negations allow you to exclude particular cases.

    How Conditional Logic Works

    The conditional logic system evaluates the provided conditions using OR logic for positive conditions and then applies negations as exclusions. This means:

    • The functionality is enabled if any positive condition is true.
    • After a positive match, any matching negated condition will exclude the functionality.

    Key points to keep in mind:

    • Positive conditions are ORed together, so if any condition is true, the check moves forward.
    • Prefix a condition with ! to negate it (e.g., !is_page=about means “exclude the about page”).
    • Negated conditions act as exclusions after positive conditions are evaluated.
    • You can combine the same condition positively and negatively (e.g., is_page&!is_page=about).

    Why Conditional Logic Uses OR

    The purpose of the Conditional Logic system is to enable functionality when any one of multiple conditions is met. This makes it easier to activate features based on a variety of contexts.

    Using OR logic means:

    • If you want a feature active on the homepage or the shop page, you can write is_home&is_shop — the feature will be enabled if either condition matches.
    • It’s simpler and more intuitive for enabling features that apply to multiple sections of the site.
    • AND logic would require all conditions to be true at the same time, which is often impossible (e.g., a page can’t be both the homepage and the cart page).
    • You can also exclude specific cases using negations (e.g., is_page&!is_page=about enables the feature on all pages except the “about” page).

    In short, OR logic allows you to say: “Enable this if any of these conditions are true, unless a negated condition excludes it.”

    Examples

    Below are a few example conditional strings you can use to control functionality based on specific conditions. Remember you can combine checks using the & symbol.

    Conditional StringMeaning
    is_pageTrue if viewing any page.
    is_page=aboutTrue if viewing the “About” page.
    is_singular=post,pageTrue if viewing a post or a page.
    is_singular=portfolioTrue if viewing a portfolio post.
    is_product_category=shoesTrue on the “shoes” product category.
    is_user_logged_inTrue if the user is logged in.
    is_front_pageTrue on the front page of the site.
    is_archive&!is_searchTrue on archives except search results.
    !has_page_headerTrue when the page header is disabled.

    Allowed Conditional Logic Tags

    Here is a list of all the allowed tags you can use for the Conditional Logic fields:

    • has_page_header_title
    • page_header_style=background-image
    • is_user_logged_in
    • is_super_admin
    • is_main_site
    • is_main_query
    • is_paged
    • not_paged
    • in_the_loop
    • is_page
    • is_page_template
    • is_singular
    • is_single
    • is_attachment
    • is_sticky
    • has_term
    • has_tag
    • has_post_thumbnail
    • is_tax
    • is_search
    • is_tag
    • is_category
    • is_archive
    • is_post_type_archive
    • is_author
    • is_date
    • is_year
    • is_month
    • is_day
    • is_time
    • is_new_day
    • is_404
    • is_home
    • is_front_page
    • is_shop
    • is_product_category
    • is_product_tag
    • is_woocommerce
    • is_wc_endpoint_url
    • wpex_is_woo_shop
    • wpex_is_woo_tax
    • wpex_is_woo_single
    • tribe_is_event
    • tribe_is_view
    • tec_is_view
    • tribe_is_list_view
    • tribe_is_event_category
    • tribe_is_in_main_loop
    • tribe_is_day
    • tribe_is_month

    How to Add your Own Tags?

    For more complex scenarios, you may want to register your own custom conditional tags. This can be done by hooking into the totaltheme/conditional_logic/conditional_tags filter like such:

    add_filter( 'totaltheme/conditional_logic/conditional_tags', function( $tags ) {
    	$tags[] = 'my_custom_condition';
    	return $tags;
    } );

    Once registered, the my_custom_condition() function will be available for use in any conditional string. This function should also be defined and return a boolean.

    Why It’s Only Available for Certain Features

    Conditional Logic is a powerful feature designed to control when specific theme functionalities are enabled. However, it’s not applied universally across all settings because:

    • Most site features should apply site-wide for design consistency and a better user experience.
    • Limiting conditional checks to key features (like the Transparent Header or Primary Bottom Spacing) ensures meaningful dynamic behavior without unnecessary complexity.
    • Applying conditional logic universally could impact performance and complicate theme settings.
    • This focused approach keeps the theme easier to maintain while giving you flexibility where it matters most.

    This targeted approach ensures Conditional Logic is used where it adds real value without unnecessary complexity.

    Related Articles
    No related articles found
    Back To Top