Is is possible to find how how many tags (and categories) a post has and to display it?

something like this: when a post has three Tags and two categories, at the end of the post show that number inside brackets, like so:


I would like to have it so, because i would like that the tag/category list is hidden until the user clicks or hovers it.

Right now i am making the Tags into an unordered list like this:




4 Answers 4


for tags you can use

$tags = get_tags();
$categories = get_categories();

$no_of_tags = count($tags);
$no_of_categories = count($categories);

refer this if you need more details : http://codex.wordpress.org/Function_Reference/get_tags http://codex.wordpress.org/Function_Reference/get_categories

  • That seems to give the number of total tags, NOT the number of tags for the post, as it was asked for May 24, 2019 at 5:59

Use this,

$tags = wp_get_post_terms($post_id, 'post_tag');
        echo 'TAGS ('.count($tags).')';

$category = wp_get_post_terms($post_id, 'category');
        echo 'Category ('.count($category).')';

for reference http://codex.wordpress.org/Function_Reference/wp_get_post_terms


Use this code on your post loop: ya display on single.php

    while ( have_posts() ) : the_post();
        $tags = wp_get_post_terms($post->ID);
         echo 'TAGS ('.count($tags).')';
         $categories = get_categories();
         echo 'CATEGORIES ('.count($categories).')';

enter image description here

  • 1
    i have just noticed that with that code i was getting always for the categories te total amount of categories in the blog. it was all the same. I ended up using $categories = wp_get_post_terms($post->ID, "category"); Jan 7, 2014 at 17:20
  • This code and above code both are right so you can any code use for your total.
    – Ravi Patel
    Jan 8, 2014 at 4:10

Taking a little bit from all of you, this is what i ended up using:

$tags = wp_get_post_terms($post->ID);
echo 'TAGS ('.count($tags).')'

$categories = wp_get_post_terms($post->ID, "category");
echo 'CATEGORIES ('.count($categories).')'

Thank you all for your quick help! =)

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.