Post Terms Separator in Bricks

When post_terms_<taxonomy> dynamic data tag is used in Bricks in an element like the “Meta Data”, the linked terms are separated by commas by default.

Note: The Separator control you see in the above screenshot is not for the individual terms, but rather the items of that element.

If you would like these to be replaced with another like | or spaces or remove them completely, we can use the bricks/dynamic_data/post_terms_separator filter like this:

add_filter( 'bricks/dynamic_data/post_terms_separator', function( $sep, $post, $taxonomy ) {
	return ' | ';
}, 10, 3 );

To remove the separator(s):

add_filter( 'bricks/dynamic_data/post_terms_separator', function( $sep, $post, $taxonomy ) {
	return '';
}, 10, 3 );

If you would like to limit to specific taxonomies:

add_filter( 'bricks/dynamic_data/post_terms_separator', function( $sep, $post, $taxonomy ) {
	if ( $taxonomy === 'testimonial_type' ) {
		return '';
	}

	return $sep;
}, 10, 3 );

where testimonial_type is the name of the taxonomy.

Get access to all 524 Bricks code tutorials with BricksLabs Pro

3 comments

  • Álvaro Massana de Castro

    In parent terms it creates a separation with a "-" of some sort. How could we change the separator for parent terms? It would be great if it could be like:
    term1 (subterm1, subterm2, subterm3), term2 term1 (subterm1, subterm2, subterm3), etc. Thank you,

  • Niels Tieman

    Would this work on relationships as well? Currently they are shown as a list.

Leave your comment

 

Related Tutorials..

Show Product Categories Count Using Bricks Filter Hook

Show Product Categories Count Using Bricks Filter Hook

Unable to find terms count from the Dynamic Data provided by Bricks theme? It's okay, this simple tutorial shows you how to properly get the…
Categories:
Tags:
How to hide/remove the Block Element from the Bricks Builder

How to hide/remove the Block Element from the Bricks Builder

Don't like the new Block element in Bricks? Just copy/paste the following code into your child theme's functions.php. By the way, It's a terrible idea…
Categories:
Tags:
How to Add a Custom Control Field to an Element in Bricks

How to Add a Custom Control Field to an Element in Bricks

In this tutorial, we'll learn how to add a custom control field to an element and dynamically change a CSS property inside the builder. Introduction…
Categories:
Tags: