Condition for if a page is built using bricks or if the page has a template assigned

Is there a condition like is_bricks() or similar that checks if a page was designed using Bricks Builder? And is there a check for a page that has a Bricks template assigned?

My use case is to write a filter or something that will check if the current page was built using Bricks or not && if the page has a template design assigned to it and to prefer the one-off Bricks page design over the template. I think this could be handled with Brick’s template scoring but honestly, I’m running into a dead end because I don’t understand the logic there.

Like, how in the heck do you get Bricks to load a regular Bricks-built design over a Bricks Template for a post type?

I’m struggling. I’m checking for post type of page. I have a template assigned to the page post type. I have certain pages that have a unique design built via bricks directly on the page. But then the post type page template is always what is displayed. I’ve tried changing the score from 0 to 9 and it makes no difference to what template loads.

add_filter( 'bricks/screen_conditions/scores', function( $scores, $condition, $post_id, $preview_type ) {
  // Check if 'postType' is set in the condition and the current post is of type 'page'
  if (isset($condition['postType']) && get_post_type() == 'page') {
    $scores[] = 0;  // Assigning a score of 0

  }

  return $scores;
}, 10, 4 );

The code seems do do something
echo 'Matched postType in condition for template ID: ' . $post_id . '. Scores: ' . implode(', ', $scores) . '<br>';

So, I think my understanding of the bricks/screen_conditions/scores is incorrect or whatever I’m doing is incorrect :upside_down_face:
Direction is appreciated.

1 Like