Shilpa
26 Feb 2022
Wordpress
I want to show all the tags available for an opened post with the customized theme page. I am using templates to show the blog posts.
To show the category I am using the below code.
$categories = get_the_category();
If I print what I am getting using the above command,
echo esc_html($categories[0]->name);
It returns data for categories.
Is there any way similar to a category, to obtain tags information and show it on the UI?
Rakshit
27 Feb 2022
Best Answer
To obtain tags, you should use the code in the below manner. Here get_the_terms()
` taxonomy will fix your issues.
$tagList = get_the_tags();
if ( is_array( $tagList ) && ! empty( $tagList ) ) {
echo esc_html( $tagList[0]->name ); //It will print all available tags.
}
To show category, use the below snippet.
$catList= get_the_category();
if ( ! empty( $catList) ) {
echo esc_html( $catList[0]->name ); //It will print all categories added to respective posts.
}
© 2025 Copyrights reserved for web-brackets.com