user image

Shilpa
Published in : 2022-02-26

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

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?

Comments

Rakshit Date : 2022-02-27

Best answers

34

Best answers

34

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

[solved] undefined $post->ID in WP_Query()
Publish date: 2022-01-30 | Comments: 2

Tag: Wordpress

How to run wordpress with different themes in main domain and subdomain?
Publish date: 2022-03-01 | Comments: 1

Tag: Wordpress

Will Google Dorking save my secure WordPress website running on HTTPS?
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

A custom WordPress Login page and URL
Publish date: 2022-02-10 | Comments: 2

Tag: Wordpress

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

Tag: Wordpress

Wordpress update button returns 404 [SOLVED]
Publish date: 2021-06-26 | Comments: 2

Tag: Wordpress