Bricks Active Template Condition

Tech Articles | March 26, 2025 | Blog, Bricks Builder, Coding, Wordpress

I saw the following question on the bricks facebook group and thought I would do a very quick write up and video as I have the time.

So the answer is yes, and its all based on the Filter: bricks/active_templates, and a good set of examples are available here:

The code snippet below allows you to do just that, conditionally applying horrible CSS to a page based on the header template

<?php
add_filter( 'bricks/active_templates', 'conditionally_enable_blue_text_for_header', 10, 3 );

function conditionally_enable_blue_text_for_header( $active_templates, $post_id, $content_type ) {
    // Define the header template IDs that should trigger the blue text
    $enabled_headers = array( 14, 456 ); // Replace with your actual header template IDs

    // Check if the active header template ID is in the list of enabled templates
    if ( isset( $active_templates['header'] ) && in_array( $active_templates['header'], $enabled_headers ) ) {
        // Add our custom style to the header
        add_action( 'wp_head', 'print_blue_text_styles', 100 );
    }

    return $active_templates;
}

function print_blue_text_styles() {
    echo '<style>body, body * { color: blue !important; }</style>';
}
PHP

I haven’t tried it, but I would assume this could be used on any of the template types that Bricks ha,s such as

  • header – The header template used globally or on specific pages.
  • footer – The footer template used globally or on specific pages.
  • content – The main content template for a specific page or post.
  • archive – The template used for archive pages (e.g., category or tag archives).
  • search – The template used for search result pages.
  • error – The template used for error pages (like 404).
  • singular – The template used for singular posts or pages.
  • page – The template specifically for static pages.
  • post – The template specifically for individual posts.
  • product – The template used for WooCommerce products (if WooCommerce is active).
  • shop – The main shop page template (WooCommerce).
  • category – The template used for category archives.
  • tag – The template used for tag archives.
  • taxonomy – The template used for custom taxonomies.
  • author – The template used for author archive pages.
  • date – The template used for date-based archives (e.g., yearly or monthly archives).

Support the Author

buy me a coffee
Really Useful Plugin Logo
Appoligies for any spelling and grammer issue. As a dyslexic i need to rely on tools for this they like me are not perfect but I do try my best