Modules / Visibility & conditions

Visibility: hide when empty

Hide element when its content is empty

Tick one box and an element disappears from the page when it renders no text, no media and no other element. Bricks can already hide an element on one empty tag (the Dynamic data condition) or on one loop's {query_results_count}. Kiln checks what the element actually renders, children included.

#7 of 39 modules by votes

  • On by default
  • Needs Bricks 2.4 or newer
  • Tested with Bricks 2.4.3
Recording: an empty promo card shows on the live page; someone ticks Hide when empty in the builder and saves, and the card is gone from the live page.Recorded in Bricks 2.4.3

How to use it

  1. Select the element: a Section, Container, Block, Div, Basic text, Rich text, Heading, Image, Button, Text link, Icon box, List or Post meta.
  2. In the Content tab, tick Hide when empty (Kiln).
  3. View the page on the front end. If the element renders empty, Kiln leaves it out of the HTML.

For a section that holds a heading and a query loop, tick Hide when its query loops are empty (Kiln) instead. The heading has text, so the section never renders empty. With this option the whole section goes when every loop inside it comes back with nothing.

Where it appears in Bricks

Section, Container, Block, Div, Basic text, Rich text, Heading, Image, Button, Text link, Icon box, List, Post meta, Content tab: Hide when empty (Kiln).

Section, Container, Block, Div, Content tab: Hide when its query loops are empty (Kiln).

What counts as empty

Kiln checks the element's rendered HTML, so it covers nested elements, dynamic data, shortcodes and templates. The element is empty when it holds none of these:

  • Visible text. Spaces, non-breaking spaces and zero-width characters do not count as text.
  • Media or interactive tags: img, picture, video, audio, iframe, svg, canvas, input, select, textarea, button, form, object, embed, hr, progress, meter and math.
  • An icon-font icon (an i tag with a class).
  • Any other Bricks element, such as an Icon, Map, Counter, Lottie or Form. Only Section, Container, Block, Div, Basic text, Rich text and Heading count as plain layout and text.

Scripts, styles, templates and noscript blocks do not count as content.

A few elements are checked differently:

  • Button, Text link, Icon box, List, Post meta: empty when they print no text and no image. Their icons, and the separators that List and Post meta print between items, do not count. A button that shows only an icon is hidden when its text comes back empty.
  • Image: empty when it prints no image. When the image's dynamic data is empty, Bricks prints nothing on its own; Kiln catches the cases where a link or caption wrapper is left behind.
  • Text you choose: under Also count as empty in the module's settings, list text that means "nothing here", one per line, such as 0, - or N/A. An element whose whole text is one of these counts as empty. Letter case is ignored.

A background image or background video chosen in the element's own style settings keeps the element on the page. A background image that comes only from your own CSS does not.

How it works with query loops

  • If the element has a query loop itself, Kiln never removes the loop element. It needs its markup for filters, AJAX pagination and live search.
  • Each item of that loop is checked on its own. Tick Hide when empty (Kiln) on a looping Block and the items that render empty drop out.
  • Hide when its query loops are empty (Kiln) looks at the loops inside the element. It hides the element when at least one loop ran and every one returned no results. Loops inside another loop's items don't count. A loop's "No results" text or template doesn't keep the element.

Limits

  • Front end only. In the builder the element stays visible and selectable.
  • If Kiln cannot read the element's HTML (for example, a very large inline script), it keeps the element.
  • The loop option decides when the page loads. If a filter later empties the loop with AJAX, the section stays; if the page loads with no results, the section is gone and a filter can't bring it back. Don't use it on a section that also holds the loop's filters: a filter value in the URL that matches nothing would remove the filters with it, and the visitor couldn't reset them.
  • The loop option sees loops placed directly in the element, including inside a component. It doesn't see loops inside a Template element or a component slot; there the element stays.

Settings

Bricks > Kiln, Visibility: hide when empty:

  • Also count as empty: text that means "nothing here", one per line, up to 20.

Requirements

Bricks 2.4 or newer.