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

Leave the first comment

 

Related Tutorials..

How to create responsive tooltips in Bricks

How to create responsive tooltips in Bricks

In this tutorial, we'll see how we can add perfectly responsive tooltips to any Bricks elements. Introduction Tooltips can be a great way to show…
Categories:
Tags:
Bricks Condition for WishList Member

Bricks Condition for WishList Member

How to render a Bricks element only if the user has access to a specified WishList Member level.
Categories:
Pro
ACF Repeater Row Count Condition in Bricks

ACF Repeater Row Count Condition in Bricks

This Pro tutorial provides the steps to output elements on single posts (of any post type) in Bricks only if a specific ACF Repeater-type of…
Categories:
Pro
Configuring Image Gallery dynamic source in Bricks

Configuring Image Gallery dynamic source in Bricks

Let's say you have a custom field created with ACF Pro of the type Gallery called "Property Gallery" for posts of "Property" CPT. In the…
Pro
Query Loop in Bricks

Query Loop in Bricks

This Pro tutorial walks you through the steps to use the Query Loop feature in Bricks to display a responsive grid of posts using CSS…
Categories:
Load more for Query loops in Bricks

Load more for Query loops in Bricks

Did you know that Bricks has AJAX loading for query loop posts on-click out of the box?
Categories: