Is there a way to assign a default page template to all pages, but without overwriting pages build with bricks, and without having to exclude every single pages we do not want to use this template.
Exemple, if we want pages made by a client in Gutenberg to use the default template, but we want something different than the default one by bricks builder.
In the child-theme, we modified the page.php template with the template shortcode and itâs working, but there should be an easier solution.
Maybe just a âDefault pageâ in the template types dropdown?
The only way I know how to do this is to apply a taxonomy to pages using something like ACF and using an acf field to pick the taxonomy for each post/page and then setting up an exclusion for the specific option e.g. (Without template) so then you can just choose option to not render the template. You could also have options for no header and footer or combinations.
Hey @JohnF,
if I understand your scenario correctly you can use the bricks/active_templates hook. In your case it should look something like this:
add_filter( 'bricks/active_templates', function( $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 ( empty( $bricks_data ) ) {
return $active_templates;
}
$active_templates['content'] = $post_id;
return $active_templates;
}, 10, 3 );
This makes sure that pages do not use the configured page template if they are built with Bricks themselves.
Let me know if it helps.
Best,
André
I wrote about this in a blog post a while back. I used a template that applies to every page, and created a function that tests if the page has Bricks content on it.
Yes! this is exacly what i was looking for.
Thank you André!
Doesnât it seem odd that we need PHP for this?
Intuitively, if I donât want to use the standard page template, I am going to be clicking the âEdit with Bricksâ button in the page editor (like, isnât this how Elementor handles it? Trying to rememberâŠ).
The default should be just that, the defaultâbut then if I choose not to use the default (ie., hand design that particular page in Bricks), then that very action of clicking âEdit with Bricksâ should override the defaultâitâs implicit.
Bricks could add a warning like âHey this is going to override the default page template for this condition - are you cool with that?â if they wanted to.