How to list out your WordPress tags with a post count for each

26 December 2018

Working on this site's HTML sitemap recently, I wanted a way of listing out all my WordPress tags (as links) with a post count for each. Something like this:

List of WordPress tags

This isn't something I was willing to create manually because then I would need to update it every time I published a new post. After a bit of Googling I found a useful snippet of php on the Mobilize Cloud website that took me most of the way there - it listed out all tags as links, but without a post count.

All it took was a slight tweak to echo the count field for the $tag variable (within brackets). The final code is below and you can see it in action on the HTML sitemap.

And this can also be adjusted to list categories instead...

Leave a Reply

Your email address will not be published. Required fields are marked *

Copyright © James Clark
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram