Deactivate links in Posts fields - for Categories

Hi there.

In the Posts element and the ‘fields’ section - it´s possible to show the categories via {post_terms_category}. By nature the categories have links.

Is it posible to deactivate the links to these categories? Cause there are no pages for them - needed.

For example the Post Title can be linked with {post_title:link}.

Is there also a way to ‘unlink’?

Hi Sascha,
Unfortunately, this is not possible right now, but you can write your own PHP function and use it inside a loop within the code block or inside of your child theme functions.php and echo it using the dynamic data syntax (since Bricks 1.4). We may be able to introduce a filter for this soon.

Something like this works in a loop for example:

<?php

$post_categories = wp_get_post_categories( get_the_ID(), array( 'fields' => 'names' ) );
 
if( $post_categories ){ 
  foreach($post_categories as $name){
    echo $name;
  }
}

?>

Best regards,
timmse

Hi Stefan.

Thx again for taking care and deliver a fast solution!

Hi @timmse, I am facing the same issue. Following your instructions, I have a term called “food”, so I modified the code you provided to get what is below.

<?php 
  $terms = get_the_terms( get_the_ID(), 'food' ); 
  foreach($terms as $term) {
    echo $term->name;
  }
?>

I then tried to use the dynamic data syntax as seen below in the text area element, but it was not working.

{echo:food}

Please advice. Thanks

There are two ways.

With echo. The “echo” tag works like this: {echo:function_name}, so for example {echo:get_the_ID}. If you create a function named “get_food” and put it inside functions.php then you use it like {echo:get_food}.

With code block. The code example given by @timmse will work in a loop when put inside a code block.

Does it mean based on the code provided, the function is get_the_terms so my dynamic php tag should be {echo:get_food} ?

Nope, this is a pure PHP that simply uses get_the_terms as one of its parts in the process of outputting these terms with later foreach. If you’re not familiar with this kind of stuff, please describe, what exactly are you trying to achieve, and I should be able to help :slight_smile: Please be specific tho :smiley:

Oh my bad, I have zero knowledge of PHP. Okay, back to my issue. I have a card with a custom tax at two locations on the card. Both are linked to the tax page, which is empty in my case. I would like to remove the link from them.

image

Could you also show, what is the structure here (what elements are used) and what is the tax name?

the taxonomy name is game and below is the structure. At the moment, the two instances of the terms {post_terms_game} are linked but i want them without the link. Thanks

image

Because you want to do this in two separate places, I recommend creating a function and using echo tag to output the result. I assume that:

  1. This is a custom taxonomy named “game”, not a default WordPress “tag” or “category”.
  2. It can take only one value.
  3. It will always have this value set.

In your functions.php (or a PHP code snippet if you use them) add

function get_game_nolink(){
    $game = get_the_terms($post->ID, 'game');
    return $game[0]->name;
}

Then in the builder, you use this as {echo:get_game_nolink}.

You can call this function however you like.

1 Like

This worked perfectly. Thank you very much. :grinning: