I am very new to wordpress development, please help me out in getting post's category name and its url.

I have tried get_the_category() function but it didn't helped me. Following it the code snippet:

     <div class="post-meta-categories"><i class="fa fa-tags"></i> <?php get_the_category(); >

To understand why get_the_category(); didn't work we have to take a closer look at the Codex page for that function. More specifically, what that function returns.

(array) Array of WP_Term objects, one for each category assigned to the post.

You tried to print an Array to HTML, which is why it didn't work.

Instead, take a look at the get_the_category_list() function as seen on the Codex, which says:

Retrieve category list in either HTML list or custom format.

You also forgot to end your php snippet with a ?>. So to wrap it all up...

<div class="post-meta-categories"><i class="fa fa-tags"></i> <?php echo get_the_category_list(','); ?></div>

Which returns a list of comma separated post categories with clickable links.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.