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

Leave the first comment

 

Related Tutorials..

Bricks Survival Guide for Oxygen Users

Bricks Survival Guide for Oxygen Users

Updated on 29 Oct 2024 Here are some tips and answers to FAQs for users switching to or considering switching to Bricks Builder from Oxygen.…
Categories:
Tags:
Copy To Clipboard Button for Sharing Your Bricks Designs

Copy To Clipboard Button for Sharing Your Bricks Designs

How to allow your visitors/site members to copy your Bricks’ element code with a single click.
Categories:
Tags:
Pro
Filtering posts by a group field’s true / false field sub field value with ACF or Meta Box in Bricks

Filtering posts by a group field’s true / false field sub field value with ACF or Meta Box in Bricks

This Pro tutorial covers how posts of a Bricks query loop can be filtered to show only the ones whose true / false or checkbox…
Categories:
Tags:
Pro
Horizontal Scrolling Sections in Bricks Using GSAP’s ScrollTrigger

Horizontal Scrolling Sections in Bricks Using GSAP’s ScrollTrigger

In this Pro tutorial we'll use GSAP's ScrollTrigger library in Bricks to create a section that will scroll horizontally across a number of full width…
Synced thumbnail sliders in Bricks using BricksExtras

Synced thumbnail sliders in Bricks using BricksExtras

Setting up post-specific synced/linked thumbnail sliders that show photos from a gallery-type custom field using BricksExtras plugin in Bricks.
Pro
Conditional Section when Post has a Featured Image in Bricks

Conditional Section when Post has a Featured Image in Bricks

This Pro tutorial provides the steps to output a Section in Bricks on single posts (of any post type) only if the post has a…
Categories:
How to change Ctrl/Cmd+Shift+V shortcut to View on frontend in Bricks

How to change Ctrl/Cmd+Shift+V shortcut to View on frontend in Bricks

Learn how to change the keyboard shortcuts for viewing on front end from Ctrl/Command + Shift + V to Ctrl/Command + Alt + V using…
Categories: