Skip to content

Conditional Logic

Alex de Borba edited this page Jun 21, 2026 · 1 revision

Conditional Logic

Aegis provides a conditional logic system that controls block visibility based on various conditions. This allows you to show or hide content dynamically without writing code.

Understanding Conditional Logic

Conditional logic determines whether a block (or group of blocks) is rendered on the frontend based on one or more conditions. Blocks with unmet conditions are completely removed from the output — they do not load hidden via CSS, which means no performance penalty for hidden content.

Condition Types

Condition Description Example
User logged in Visitor is authenticated Show member-only content
User logged out Visitor is not authenticated Show login prompts
User role Visitor has a specific role Show admin tools
Page type Current page matches a type Show only on blog posts
Device type Viewport matches a breakpoint Show mobile-specific content
Date/time Current date or time matches Show seasonal banners
WooCommerce cart Cart has items or is empty Show cart reminders
Query parameter URL contains a parameter Show campaign-specific content
Referrer Visitor came from a source Show welcome messages

Applying Conditions to Blocks

In the Block Editor

  1. Select any block or Group block.
  2. In the block settings sidebar, locate the Conditions section (under Advanced).
  3. Click Add Condition.
  4. Choose the condition type from the dropdown.
  5. Configure the condition parameters.
  6. Optionally add multiple conditions (AND/OR logic).
  7. Save or update the page.

Using Groups for Multiple Blocks

To apply a condition to multiple blocks at once:

  1. Wrap the target blocks in a Group block.
  2. Apply the condition to the Group block.
  3. All child blocks inside the group will follow the same visibility rule.

Condition Configuration

User Authentication

Setting Options
State Logged in / Logged out

Shows or hides content based on whether the visitor is authenticated.

Use cases:

  • Display "Welcome back" messages to logged-in users.
  • Show registration prompts to visitors.
  • Display member-exclusive content.

User Role

Setting Options
Role Administrator, Editor, Author, Subscriber, Customer, or any custom role
Match Has role / Does not have role

Use cases:

  • Admin-only notices.
  • Subscriber-exclusive content.
  • WooCommerce customer content.

Page Type

Setting Options
Type Front page, Blog page, Single post, Page, Archive, Search, 404

Use cases:

  • Show a newsletter signup only on blog posts.
  • Display breadcrumbs only on inner pages.
  • Show search tips on the search results page.

Date and Time

Setting Options
Start date Content visible after this date
End date Content hidden after this date
Days of week Content visible on selected days
Time range Content visible during specified hours

Use cases:

  • Holiday banners visible only during December.
  • Lunch menu visible during business hours.
  • Event countdown visible until the event date.

WooCommerce Conditions

Setting Options
Cart status Has items / Is empty
Product in cart Specific product is/is not in cart
Customer purchased Customer has/has not purchased a product

Use cases:

  • Cross-sell banners when specific products are in the cart.
  • "Your cart is empty" messaging.
  • Post-purchase thank you content.

Combining Conditions

AND Logic

When multiple conditions are set on the same block, ALL conditions must be true for the block to display:

  • User is logged in AND current page is a single post AND date is before December 31.

OR Logic

To create OR logic, duplicate the block with different conditions:

  • Block A: Show if user role is Administrator.
  • Block B: Show if user role is Editor.

Both blocks contain the same content but display based on different conditions.

Performance Impact

Conditional logic is evaluated server-side during rendering:

  • Blocks that do not meet their conditions are removed before HTML output.
  • No hidden HTML is sent to the browser for conditional blocks.
  • No JavaScript is needed for condition evaluation.
  • No additional database queries for basic conditions (logged in, page type).

Template-Level Conditions

Conditions can also be applied at the template level:

  1. In the Site Editor, edit a template.
  2. Apply conditions to sections within the template.
  3. Different visitors see different template sections based on conditions.

Example: The header template part could show a "Log In" button for guests and a "My Account" link for authenticated users.

Best Practices

  • Use Groups — Wrap related conditional content in a Group for cleaner management.
  • Test both states — Preview your page as both a logged-in and logged-out user.
  • Avoid over-using conditions — Too many conditional blocks can make editing confusing.
  • Document conditions — Use block descriptions or comments to note why conditions exist.
  • Consider caching — Pages with user-specific conditions may need appropriate cache configuration.

Caching Considerations

When using user-specific conditions (logged in, role, cart status):

  • Full page caching may need to be excluded for pages with user-specific conditions.
  • Fragment caching can be used to cache the public portions separately.
  • ESI (Edge Side Includes) can handle user-specific sections at the CDN level.
  • Privacy-focused providers like Plausible are not affected by conditional caching.

Next Steps

Clone this wiki locally