---
title: Bricks Active Template Condition
date: 2025-03-26T17:49:54Z
modified: 2026-09-22T19:51:44Z
permalink: "https://techarticles.co.uk/bricks-active-template-condition/"
type: post
status: publish
excerpt: ""
wpid: 4712
categories:
  - Blog
  - Bricks Builder
  - Coding
  - Wordpress
timestamp: 2026-09-22T19:51:44Z
tags:
  - 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.

![Is it possible to enable/disable a WPCodeBox snippet based on Bricks template activation? Looking for insights on Condition Builder use.](https://techarticles.co.uk/wp-content/uploads/2025/03/Question.png)

So the answer is yes, and its all based on the Filter: bricks/active\_templates, and a good set of examples are available [here](https://academy.bricksbuilder.io/article/filter-bricks-active_templates/):

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>’; } ```
<span class="line"><span style="color: #F97583"><?</span><span style="color: #79B8FF">php</span></span>
<span class="line"><span style="color: #B392F0">add_filter</span><span style="color: #E1E4E8">( </span><span style="color: #9ECBFF">'bricks/active_templates'</span><span style="color: #E1E4E8">, </span><span style="color: #9ECBFF">'conditionally_enable_blue_text_for_header'</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">10</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">3</span><span style="color: #E1E4E8"> );</span></span>
<span class="line"></span>
<span class="line"><span style="color: #F97583">function</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">conditionally_enable_blue_text_for_header</span><span style="color: #E1E4E8">( $active_templates, $post_id, $content_type ) {</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #6A737D">// Define the header template IDs that should trigger the blue text</span></span>
<span class="line"><span style="color: #E1E4E8">    $enabled_headers </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">array</span><span style="color: #E1E4E8">( </span><span style="color: #79B8FF">14</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">456</span><span style="color: #E1E4E8"> ); </span><span style="color: #6A737D">// Replace with your actual header template IDs</span></span>
<span class="line"></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #6A737D">// Check if the active header template ID is in the list of enabled templates</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> ( </span><span style="color: #79B8FF">isset</span><span style="color: #E1E4E8">( $active_templates[</span><span style="color: #9ECBFF">'header'</span><span style="color: #E1E4E8">] ) </span><span style="color: #F97583">&&</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">in_array</span><span style="color: #E1E4E8">( $active_templates[</span><span style="color: #9ECBFF">'header'</span><span style="color: #E1E4E8">], $enabled_headers ) ) {</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #6A737D">// Add our custom style to the header</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #B392F0">add_action</span><span style="color: #E1E4E8">( </span><span style="color: #9ECBFF">'wp_head'</span><span style="color: #E1E4E8">, </span><span style="color: #9ECBFF">'print_blue_text_styles'</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">100</span><span style="color: #E1E4E8"> );</span></span>
<span class="line"><span style="color: #E1E4E8">    }</span></span>
<span class="line"></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> $active_templates;</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color: #F97583">function</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">print_blue_text_styles</span><span style="color: #E1E4E8">() {</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #79B8FF">echo</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">'<style>body, body * { color: blue !important; }</style>'</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span>
<span class="line"></span>
```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).

![](https://i.ytimg.com/vi/JnXJdCKWiYs/maxresdefault.jpg)