8th Apr '24
/
0 comments

Checking if a Page has Bricks content

Looking to conditionally render elements in Bricks if the current Page (or post of any post type for which editing with Bricks has been enabled) has no Bricks content?

Add the following in child theme‘s functions.php (w/o the opening PHP tag) or a code snippets plugin:

function bl_has_bricks_content(): bool {
    $bricks_data = \Bricks\Database::get_data( get_the_ID(), 'content' );

    return $bricks_data ? true : false;
}

To output an element if the Page does not have Bricks content:

{echo:bl_has_bricks_content}

Whitelist the bl_has_bricks_content function.

This also works for Pages that are rendered by a Bricks template.

Get access to all 633 Bricks code tutorials with BricksLabs Pro

Leave the first comment

 

Related Tutorials..

Sticky Header in Bricks

Sticky Header in Bricks

Updated on 15 Nov 2022 Bricks has a handy sticky feature that enables us to build two types of sticky headers: Also, we can specify…
Categories:
How To Remove the Featured Image from WooCommerce Product Gallery

How To Remove the Featured Image from WooCommerce Product Gallery

Product Gallery on single product pages in WordPress include the product's featured image by default. If you are looking to exclude it so only the…
Categories:
Pro
Dynamic Google Map in Bricks – Markers from ACF Repeater Google Map Sub Field Values

Dynamic Google Map in Bricks – Markers from ACF Repeater Google Map Sub Field Values

This Pro tutorial provides the steps to show the addresses entered using a Google Map sub field of a ACF Repeater as markers on a…
Categories:
Pro
Adding CSS based on a PHP boolean value in WordPress

Adding CSS based on a PHP boolean value in WordPress

In the Bricks Facebook group a user asked: How do I display a pseudo element depending on the presence of data in an ACF field…
How to display CPT’s singular_label in Bricks

How to display CPT’s singular_label in Bricks

Looking to get and output a post type's singular label in Bricks on single CPT pages? Define a custom function by adding the following in…
Categories:
Condition based on WooCommerce Product Attributes in Bricks

Condition based on WooCommerce Product Attributes in Bricks

How to display elements only when a specific WooCommerce product attribute is selected.
Categories:
Post-specific Dynamic Info Popup in Bricks

Post-specific Dynamic Info Popup in Bricks

This tutorial provides the steps to show post-specific data (post title and post content) in a popup using Bricks' Popup Builder and Interactions features. Step…
Categories:
Pro
Child Pages on Parent Page and Sibling Pages on Child Pages

Child Pages on Parent Page and Sibling Pages on Child Pages

A user asks: I have a parent page with 10 child pages. I will display a sidebar where I display links to the child pages.…
Categories:
Pro
Bricks Slider Images From ACF Flexible Content Sub Field

Bricks Slider Images From ACF Flexible Content Sub Field

Consider the following field group associated with Pages when using ACF Pro: "Page Fields" field group|_"Page Content" Flexible Content field|__"Layout 1" layout|___"Title" Text field|___"Layout 1…