24th Jun '25
/
0 comments

Term-specific single post template in Bricks

Updated on 25 Jun 2025

In Reddit a user asks:

Template conditional logic to exclude pages with a particular taxonomy term?

I can’t figure out if it’s possible, I have two single post templates for a CPT with a custom taxonomy. I’d like to use one for the majority, and the second for posts that have a specific term in the taxonomy. The template conditions allow you to exclude a term (my term shows up) but it ignores that exclusion when rendering a page. It seems the “Term” template condition only applies to archives of that term, not a single post with that term. How can I do that?

I tried googling it but everything I’ve seen talks about archive pages and not single pages with a term.

Update

This can be done using the built-in template condition settings of Bricks w/o writing code.

Create your term-specific single template, edit it with Bricks and


Bricks has an amazing filter called bricks/active_templates that enable us to programmatically assign templates to different types of content.

Let’s say you have a Bricks template named “Single Post” of type Single that’s set to apply to all posts and now you have a special category called “Featured” and you want that any post that is assigned to this category be rendered using a different Bricks template named say, “Single Post in Featured Category”.

This can be done using the bricks/active_templates filter like so.

Add the following in child theme‘s functions.php (w/o the opening PHP tag) or a code snippets plugin:

add_filter( 'bricks/active_templates', function( $active_templates, $post_id ) {
  // Check if we're on a single post
  if ( is_singular( 'post' ) ) {
    // Get the current post object
    $post = get_post( $post_id );
    
    // Check if the post has a specific term
    if ( has_term( 'featured', 'category', $post ) ) {
      // Replace 92 with your template ID
      $active_templates['content'] = 92;
    }
  }
  
  return $active_templates;
}, 10, 2 );

where

  • post in if ( is_singular( 'post' ) ) { is the post type
  • featured is the slug of the category/taxonomy term
  • category is the taxonomy
  • 92 is the ID of your “Single Post in Featured Category” Bricks template
Get access to all 624 Bricks code tutorials with BricksLabs Pro

Leave the first comment

 

Related Tutorials..

Pro
Outputting Only the First ACF Repeater Row in Bricks

Outputting Only the First ACF Repeater Row in Bricks

Updated on 12 Dec 2023 In the Bricks Facebook group a user asks: How can I display only the first entry from an ACF repeater?…
How to create filters with IsotopeJS in Bricks (Part 4): AJAX filter and infinite loops, Sorting, List view and Disable animations

How to create filters with IsotopeJS in Bricks (Part 4): AJAX filter and infinite loops, Sorting, List view and Disable animations

This tutorial will explain how to enable the AJAX filter with an infinite scroll query loop container, how to add a sorting function, how to…
Categories:
Pro
Making a Nav Menu Item Active for Custom Post Type Single Views in WordPress

Making a Nav Menu Item Active for Custom Post Type Single Views in WordPress

Consider this scenario: CPT: project Page titled "Project" is being used to show a list/grid of all the projects rather than the CPT archive. When…
Categories:
How to Remove Name and Website Fields in Bricks Comment Forms

How to Remove Name and Website Fields in Bricks Comment Forms

Updated on 14 Mar 2024 In the BricksLabs Facebook group a user asked: What is the best method to remove fields from the Bricks "Comments"…
Pro
Filtering a Bricks Terms query on Term archive pages

Filtering a Bricks Terms query on Term archive pages

On product category archives, how to show product type names but only those that the current product category has.
Pro
How to programmatically add a class to an element in Bricks

How to programmatically add a class to an element in Bricks

This Pro tutorial shows how a dynamic class can be added to a query loop element in Bricks programmatically. Let's take an example where posts…