How to find the number of Tags a post has?

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:

Read More

TAGS (3) | CATEGORIES (2)

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:

the_tags('<ul><li>','</li><li>','</li></ul>');

thanks!

Related posts

4 comments

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

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

    enter image description here

  2. 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! =)

Comments are closed.