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 630 Bricks code tutorials with BricksLabs Pro

Leave the first comment

 

Related Tutorials..

Pro
Events grouped by Event Date custom field in Bricks

Events grouped by Event Date custom field in Bricks

This Pro tutorial for Bricks users provides the steps to output posts of an event custom post type dynamically grouped by the value of their…
Categories:
Pro
How to hide Bricks Query Loop Posts until WP Grid Builder Facets are applied

How to hide Bricks Query Loop Posts until WP Grid Builder Facets are applied

How to hide the Bricks QL posts until there’s an interaction by the user on the frontend like ticking a category or typing in a…
Categories:
Floats in Bricks for Wrapping Text Around Images

Floats in Bricks for Wrapping Text Around Images

In the Bricks Facebook group a user asks: Float, left or right? Just a quick question. Am I going crazy or can't I specify a…
Categories:
Tags:
HappyFiles Bricks Query Loop

HappyFiles Bricks Query Loop

This tutorial explores different ways in which images from WordPress Media Library organized via HappyFiles can be pulled and shown in Bricks using query loop(s).…
Categories:
Bricks single mode – Limiting the number of posts to 1 in the editor

Bricks single mode – Limiting the number of posts to 1 in the editor

Creating a "Single Mode" for Bricks query loops to make sure only one post is rendered in the builder.
How to display a Query Loop in 3 columns in Bricks

How to display a Query Loop in 3 columns in Bricks

This tutorial provides the builder settings and CSS codes that can be pasted in order to create a 3-columns query loop container inside Bricks Builder.
Categories: