Aleš Sýkora / November 28, 2023 / 5 comments
Display post tags without links in Oxygen builder
2 min read / Custom Code, Oxygen Builder, Plugins, WordPress / Share on: Twitter, LinkedIn, Facebook
Post summary: If you add the post_tag by dynamic data option in text block – for example in post or in repeater – then it displays the tag as a link to the tag’s archive. You can do the same to display categories without links in Oxygen builder. But what if you don’t want the tag archive…
If you add the post_tag by dynamic data option in text block – for example in post or in repeater – then it displays the tag as a link to the tag’s archive.
You can do the same to display categories without links in Oxygen builder.
But what if you don’t want the tag archive link? Add this function to the Oxygen Code block:
<?php
$tags = get_the_tags();
if ($tags) {
foreach($tags as $tag) {
echo $tag->name . ' ';
}
}
?>
If you want to change the separator, change this:
echo $tag->name . ' ';
To whatever you want… for example:
echo $tag->name . '||||||||||||my fancy separator||||||||||';
If you need to use this code on more than one page, I suggest you create it as a function and put to the code snippets or advanced scripts:
<?php function great_tit_tagnames() {
$tags = get_the_tags();
if ($tags) {
foreach($tags as $tag) {
echo $tag->name . ' ';
}
}
}
?>
And then just add the Text block > Dynamic Data > PHP function return value
That will generate this Oxygen shortcode, which you can use sitewide with function in one place.
[oxygen data='phpfunction' function='great_tit_tagnames']
Another solution is using code block as a re-usable block.
Fuel my passion for writing with a beer🍺
Your support not only makes me drunk but also greatly motivates me to continue creating content that helps. Cheers to more discoveries and shared success. 🍻
Labuche
Hello,
Is it possible to use it in a repeater by specifying an argument in the PHP function ? And how can i do ?
Thanks,
Tim
Is this also possible with categories?
How would the code look for categories?
Thank you, Tim
Aleš Sýkora
You don’t need to specify arguments, just put it inside the card in repeater and it should work out of the box. You don’t need to use the Shortcode, you can use the text field with dynamic data PHP value if you need.
Tim
You are amazing, thank you!
Aleš Sýkora
Here you go Display Post Categories Without Links In Oxygen Builder