Skip to content

Instantly share code, notes, and snippets.

@codysmith44
Last active March 4, 2024 21:29
Show Gist options
  • Save codysmith44/d90c3b7a09d934ca27feaf905e151a29 to your computer and use it in GitHub Desktop.
Save codysmith44/d90c3b7a09d934ca27feaf905e151a29 to your computer and use it in GitHub Desktop.
'Edit with Bricks' workflow snippet
/*
*
Allows you to use the 'Edit with Bricks' button to override templates. For instance,
you may have a template for most/all 'Pages' but need to override a specific page.
This allows you to do so without going into the Bricks template and setting conditions.
See https://academy.bricksbuilder.io/article/filter-bricks-active_templates/ for more info.
*
*/
add_filter( 'bricks/active_templates', 'cls_set_active_templates', 10, 3 );
function cls_set_active_templates( $active_templates, $post_id, $content_type ) {
if ( ! bricks_is_frontend() ) {
return $active_templates;
}
if ( $content_type !== 'content' ) {
return $active_templates;
}
$post_type = get_post_type( $post_id );
if ( $post_type !== 'page' ) {
return $active_templates;
}
$bricks_data = \Bricks\Database::get_data( $post_id, 'content' );
if ( count( $bricks_data ) > 0 ) {
$active_templates['content'] = $post_id;
}
return $active_templates;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment