Skip to content

Visibility Rules

Visibility rules control when an element is rendered on the page. Unlike display: none (which hides the element but still renders it), visibility rules prevent the element from being included in the HTML output entirely.

Visibility Modes

Always Visible (default)

The element is always rendered. This is the default for all elements.

Expression

The element is rendered only when a custom expression evaluates to true.

Example expressions:

row.status == 'active'

Only show when the current row's status is "active".

row.price > 0

Only show when the price is positive.

count(row.items) > 0

Only show when items array is not empty.

row.type == 'premium' and user_can('read')

Show only for premium items to logged-in users.

row.image_url != ''

Only show the image element when an image URL exists.

Logged In

The element is rendered only for authenticated WordPress users. Anonymous visitors do not see it.

Use cases:

  • User profile menus
  • "My Account" links
  • Edit/delete buttons
  • Personalized content sections

Logged Out

The element is rendered only for anonymous (not logged-in) visitors. Authenticated users do not see it.

Use cases:

  • Login/register buttons
  • "Sign up" call-to-action banners
  • Guest welcome messages

How It Works

Visibility rules are evaluated on the server during rendering:

  1. always -- Element is always included in HTML output.
  2. expression -- The expression is evaluated using the current data context (row). If truthy, the element is rendered; if falsy, it is skipped entirely.
  3. logged_in -- Checks is_user_logged_in(). Renders only if true.
  4. logged_out -- Checks is_user_logged_in(). Renders only if false.

Because this is server-side rendering, hidden elements are never sent to the browser. This is more secure than client-side hiding (CSS display: none) because the HTML and data are not exposed.

Expression Context

In expression-based visibility rules, the following variables are available:

VariableDescription
rowThe current data context (e.g., the current repeater row).

You can use all expression functions:

user_can('manage_options')
user_has_role('subscriber')
in_store('favorites', row.id)
row.quantity > 0 and row.status == 'active'

Common Patterns

Show edit button only for the item's author

row.user_id == user_meta('ID')

Show "sold out" badge when quantity is zero

row.quantity <= 0

Show admin toolbar only for administrators

user_can('manage_options')

Show "no results" message when data is empty

Set on a text element:

count(row.items) == 0

Show premium content only for subscribers

user_has_role('subscriber') or user_has_role('administrator')

Best Practices

  1. Use visibility for security-sensitive content. Elements hidden by visibility rules are never sent to the browser, making them safe for hiding admin controls and sensitive data.
  2. Prefer visibility over If/Else for simple show/hide. If you just need to show or hide a widget based on a condition, a visibility rule is simpler than building a conditional pipeline.
  3. Combine with auth functions. Use user_can() and user_has_role() for permission-based visibility.
  4. Keep expressions simple. Complex logic is better handled in the pipeline with If/Else or Switch nodes.