Create/Modify a default page template without having to exclude all the other pages

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?

2 Likes

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.

1 Like

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é

2 Likes

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.

1 Like

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.

1 Like