Aleš Sýkora / August 25, 2022 / 3 comments
Display post categories without links in Oxygen builder
1 min read / Custom Code, Oxygen Builder, Plugins, WordPress / Share on: Twitter, LinkedIn, Facebook
Post summary: If you want display post categories without the links in repeater or in post page without link to the category archive, you can use the code below. If you want to change the separator, change this: To whatever you want… for example: If you need to use this code on more than one page, I…
If you want display post categories without the links in repeater or in post page without link to the category archive, you can use the code below.
<?php
foreach (get_categories() as $category){
echo $category->name . ' ';
}
?>
If you want to change the separator, change this:
echo $category->name . ' ';
To whatever you want… for example:
echo $category->name . '||||||||||||my fancy separator||||||||||';
If you need to use this code on more than one page, I suggest you to create it as a function and put to the code snippets or advanced scripts plugin:
<?php function great_tit_catnames() {
foreach (get_categories() as $category){
echo $category->name . ' ';
}
}
?>
And then just add the Text block > Dynamic Data > PHP function return value and to the first input add the “great_tit_catnames”. That will generate this Oxygen shortcode, which you can use sitewide with function in one place:
[oxygen data='phpfunction' function='great_tit_catnames']
Another solution would be 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. 🍻
Guillaume
I think the right function to call is get_the_category() instead to call all the categories of your blog and not only those of the post.
Aleš Sýkora
Hello Guillaume, the get_the_category function, return info about one specific category. Not assigned categories.
Guillaume
Thanks for this tip, it’s useful.