-
-
Notifications
You must be signed in to change notification settings - Fork 1
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.
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 | 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 |
- Select any block or Group block.
- In the block settings sidebar, locate the Conditions section (under Advanced).
- Click Add Condition.
- Choose the condition type from the dropdown.
- Configure the condition parameters.
- Optionally add multiple conditions (AND/OR logic).
- Save or update the page.
To apply a condition to multiple blocks at once:
- Wrap the target blocks in a Group block.
- Apply the condition to the Group block.
- All child blocks inside the group will follow the same visibility rule.
| 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.
| 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.
| 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.
| 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.
| 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.
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.
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.
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).
Conditions can also be applied at the template level:
- In the Site Editor, edit a template.
- Apply conditions to sections within the template.
- 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.
- 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.
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.
- hook-patterns — Another way to inject dynamic content.
- block-patterns — Use conditions within pattern-based layouts.
- woocommerce-integration — WooCommerce-specific conditions.
- performance — How conditions interact with the loading strategy.
Aegis version 1.0.0 | GitHub Repository | Report an Issue | Atmostfear Entertainment
License: GPL-2.0-or-later