1st Aug '24
/
4 comments

Condition for checking Bricks content

In the comments section of The Perfect Bricks Page Template tutorial, a user asks:

Could this be modified so that instead of has_blocks it used something like has_bricks? I'd like to take the structure that you have (Gutenberg Content section followed by Bricks div) and have it render the Gutenberg content only if the page isn't built with Bricks and use the Bricks div only if the page IS built with Bricks.It's a small distinction, but it's because I often will build a page with Bricks and put the WPcontent element in the layout somewhere. When I do, I won't want the first section (Gutenberg) to display because then there would be duplication.Currently I use a similar setup where the two sections display based on a Metabox switch on each page. I'd prefer to not have to toggle that switch because it often gets forgotten.

This Pro tutorial provides the steps to define a custom function that returns true or false depending on whether the current post (typically, a Page) has Bricks content and using the function with a dynamic data Bricks condition to output Bricks content when a Page is built with Bricks or WordPress content when there is no Bricks content.

Step 1

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

This is a BricksLabs Pro tutorial.

For full access login below or create your BricksLabs Pro account

Get access to all 610 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

JetEngine Checkbox Condition in Bricks

JetEngine Checkbox Condition in Bricks

How elements in Bricks can be conditionally output depending on the selected option from a JetEngine checkbox field.
Categories:
Tags:
[Function] Current Term Has Children

[Function] Current Term Has Children

Updated on 20 Jul 2024 A user asks: I'm working on an archive template for WooCommerce products. I'm trying to hide a section if there…
Pro
Checking ‘PublishPress Future’ plugin’s Future Action enabled posts

Checking ‘PublishPress Future’ plugin’s Future Action enabled posts

PublishPress Future is a handy plugin for scheduling actions like unpublishing or deleting posts (of any post type) at a specified date and time in…
Categories:
Conditional Output based on Manual Excerpt in Bricks

Conditional Output based on Manual Excerpt in Bricks

How to display a post’s excerpt only if it has been manually set.
Categories:
Pro
Conditionally Outputting Query Loop Item Based on Post Meta in Bricks

Conditionally Outputting Query Loop Item Based on Post Meta in Bricks

Rendering query-loop enabled posts depending on the value of each post's custom field value is tricky because by default, the custom field plugins' functions or…
Categories: