I’m trying to fill the category description/text and have the category name change based on the category page you are on.
For example this category description:
You are watching [category].
If you are on the category page with the name drinks, it should change the description/text to:
You are watching drinks.
I tried to use the solution for retrieving the category name on this site, but that uses the product to show the category it belongs with. I’m trying to get the category name without any product, just the name of the category to fill the shortcode.
2
Answers
You should be able to use
single_term_title()
in a custom shortcode:If you want it to say the same thing each time you can add the text as a prefix:
You can use this shortcode with prefix attribute.
add this code in your theme’s functions.php file then add the shortcode in your archive.php file.
example :-
do_shortcode('[category prefix="You are watching "]');
Or you can leave blank if you don’t need the prefix like
do_shortcode('[category]');
.Reference :- https://developer.wordpress.org/reference/functions/single_term_title/