• Hi there,

    I was wondering if anyone had a nice clean & simple way of outputting the total amount of tags used on a wordpress site as just a plain number.

    Each time I add a new post I use a tag to place it into a film genre (eg Horror etc). I want to have something like:

    Movies: 234
    Genres: 142

    I have found a way to count and output a number of the amount of posts within the ‘Movie’ category

    <?php echo wp_count_posts()->publish; ?>

    So I am looking for something as simple to display the number of tags used. I am really surprised I am having as much trouble finding a solution as I am as this (to me) seems like a pretty basic and useful thing to add to the Codex.

    Any ideas would be awesome. Thanks guys 🙂

Viewing 6 replies - 1 through 6 (of 6 total)
  • $number_of_tags = count(get_terms($taxonomy, $args));

    If you are not using custom taxonomies, then $taxonomy would be ‘post_tag’ (or ‘post_tags’, can’t remember which it is).

    Check out this for details of the available arguments – Function Reference/get terms

    Thread Starter mradamw

    (@mradamw)

    Hey man, thanks VERY much for the reply.

    I have added the following to my sidebar.php file, but nothing shows up in the stats div (please see the code below). I apologise if I have done something horrifically stupid as my php knowledge is about on par with that of a tomato

    <div class="stats">
    <span><?php $number_of_tags = count(get_terms('post_tags')); ?></span>
    <em>Genres and counting...</em>
    </div>

    The <span> tags are there so I can target the tag count to change colour and font size.

    Thanks

    <?php $number_of_tags = count(get_terms('post_tags')); ?> Will put the number in to a variable called $number_of_tags. You should chage the above line to <?php echo count(get_terms('post_tags')); ?> to write the number on the screen.

    Thread Starter mradamw

    (@mradamw)

    Thanks again for your reply.

    I popped this code into my sidebar.php

    <div class="stats">
    <span><?php echo count(get_terms('post_tags')); ?></span>
    <em>Tags and counting...</em>
    </div><!--end stats-->

    And it did indeed output a number (yay) unfortuntaly the number is wrong. Currently i have 39 tags used on my site, but the number shown from that code is “1”

    Any ideas?

    Thanks for your help

    Thread Starter mradamw

    (@mradamw)

    Does anyone have any ideas for this?

    If you’re still interested in this topic here you have

    <?php echo wp_count_terms('post_tag'); ?>

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Display total tag count on website’ is closed to new replies.