user image

Published in : 2022-02-26

How to display tags on each posts for customized wordpress theme?


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 Date : 2022-02-27

Best answers


Best answers


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.

Leave a comment

Join us

Join our community and get the chance to solve your code issues & share your opinion with us

Sign up Now

Related posts

Issue with generating Thumbnails for PDF file format.
Publish date: 2022-02-26 | Comments: 1

Tag: Wordpress

What is the best reference to the most used WordPress functions?
Publish date: 2022-02-09 | Comments: 2

Tag: Wordpress

Way to disable Block URLs for WordPress Posts
Publish date: 2022-02-26 | Comments: 2

Tag: Wordpress

Add custom fields in user profile and display in Dashboard
Publish date: 2021-07-27 | Comments: 6

Tag: Wordpress

creating custom gallery
Publish date: 2021-09-12 | Comments: 4

Tag: Wordpress

Will Google Dorking save my secure WordPress website running on HTTPS?
Publish date: 2022-02-26 | Comments: 1

Tag: Wordpress

[solved] How to change privacy policy text above place order button Woocommerce?
Publish date: 2022-01-08 | Comments: 2

Tag: Wordpress

Cpanel to Webmin migration 503 error
Publish date: 2021-08-12 | Comments: 4

Tag: Wordpress