In some cases, you need to get title of current taxonomy. For example, you are making description in category and you want to use title of category in description, but you don’t want to type it each time (maybe you use some kind of autogeneration). Here is shortcode which you can use to get taxonomy name
// Add Shortcode
function rh_get_tax_title( $atts ) {
// Attributes
$atts = shortcode_atts(
array(
'taxonomy' => 'category',
),
$atts
);
$tagid = get_queried_object()->term_id;
$tagobj = get_term_by('id', $tagid, $atts['taxonomy']);
$tagname = $tagobj->name;
return $tagname;
}
add_shortcode( 'rh_get_tax_title', 'rh_get_tax_title' );
Place in your functions.php How to customize theme
How to use it? SImple. Use
[rh_get_tax_title taxonomy=dealstore]
It’s example how to get Title from custom taxonomy dealstore