Menu
All plugins

Hide When Empty for Bricks

A Bricks extension (no new element) for the Section, Container, Block and Div elements. Tick one box and the element disappears from the page when it renders no text, no media and no other element. Optionally name something it must contain, and it disappears when that is missing.

Version: 0.2.0 · Requires: Bricks · See the live demo

Installation

  1. Upload and activate the plugin. Bricks must be active.
  2. Select a Section, Container, Block or Div in Bricks. The Hide when empty group is on the Content tab.
  3. Switch on Hide element when its content is empty.

Settings

  • Hide element when its content is empty (default: Off)
  • Or hide when this is missing (default: blank). A simple CSS selector. See Hide when something is missing below.

Quick start

  1. Build a section whose content comes from dynamic data, a query loop or elements with conditions.
  2. Open its Hide when empty group and tick the box.
  3. View the page. When nothing in the section renders, the section is gone. When something does, it stays.

Hide when something is missing

Sometimes a section is never completely empty because it keeps a heading or an intro line, yet it is pointless without its list. With the box ticked, set Or hide when this is missing to a simple CSS selector, for example .gs-trip. The element is removed when nothing inside it matches the selector, even if it still has a heading or text.

  • Supported: tags, #ids, .classes, spaces (descendant), > (child) and commas (any of).
  • A selector the plugin cannot read never hides anything, and neither does markup it cannot parse.
  • The box must be ticked for the selector to apply. When a selector is set, it replaces the empty check: the element stays whenever the selector matches, and goes when it does not.

How it works

Bricks can already hide an element on one empty tag (the Dynamic data condition) or on one loop’s 0. This plugin checks what the section actually renders, children included, after the section and all its children have rendered. Elements hidden by conditions, empty query loops and empty dynamic data therefore all count as empty, with no per-tag setup. An empty section is removed from the HTML, not hidden with CSS.

What counts as content

  • Any visible text. Spaces, non-breaking spaces and zero-width characters do not count.
  • Media and form controls: images, pictures, video, audio, iframes, SVG, canvas, buttons, selects, textareas and visible inputs.
  • Icon fonts, inline background images, and Bricks elements that draw without text: divider, map, progress bar, counter, pie chart, rating and countdown.

What does not count

  • Empty containers, blocks, Text and Heading elements.
  • Hidden inputs, comments, scripts and styles.

Tips

  • Put a section heading and an optional card list in one section, set the selector to the card class, and the whole band goes when the list has no cards.
  • Use it on sections that pull in optional content, such as a related-articles band, a testimonials strip or a gallery section.
  • Combine it with a query loop. When the loop has no results, the whole section, heading included, disappears.

Troubleshooting

  • The section is still there — something in it renders. With a selector set, check that the selector matches nothing at all in the rendered page source. A divider, an icon or an image counts as content even with no text.
  • The section is there in the builder — expected. Sections are never removed in the builder.
  • The section is removed but I expected content — content added by JavaScript after page load is not seen. The check runs on the HTML from the server.

For developers

  • nl_hwe/elements filters which Bricks elements get the control group (default: section, container, block, div).
  • nl_hwe/content_tags filters the tags that always count as content.
  • nl_hwe/content_element_classes filters the brxe-* element names that always count as content.
  • nl_hwe/is_empty has the last word on whether a section is empty. It receives the result and the section’s markup.

Known limits

  • Not applied inside the builder.
  • A background image set in the section’s own Bricks styles is not checked.
  • If the markup cannot be parsed, the section is kept.