I am trying to remove the parentheses from the tag cloud widget and add in <span class="post_count"> </span> in place of it.

Currently I have not been having any luck. I have this working for categories just fine but not sure why it won't work for the tag cloud count.

function categories_postcount_filter ($variable) {
$variable = str_replace('(', '<span class="post_count"> ', $variable);
$variable = str_replace(')', ' </span>', $variable);
return $variable;

Any help would be much appreciated! Thanks so much!


  • In WP 4.8 there is a checkbox to toggle the count in the admin area. Prior to WP 4.8 there was no counter displayed for the default tags widget. Jun 21, 2017 at 20:48
  • 1
    Hi Dave. Exactly. I am trying to remove the parentheses that show when they do have that option checked to show the count.
    – Ponte
    Jun 21, 2017 at 20:56

1 Answer 1


this is an example output of an tag cloud widget element (wp4.8):

<a href="http://localhost/wp-beta-test/tag/handcrafted/" class="tag-cloud-link tag-link-327 tag-link-position-22" style="font-size: 8pt;" aria-label="handcrafted (2 items)">handcrafted<span class="tag-link-count"> (2)</span></a>

as you can see, the widget outputs some aria lable also using parentheses, which interferes with a simple string replace. the tag number including the parentheses is also already wrapped in a span.

for example, try to use:

function tagcloud_postcount_filter ($variable) {
$variable = str_replace('<span class="tag-link-count"> (', ' <span class="post_count"> ', $variable);
$variable = str_replace(')</span>', '</span>', $variable);
return $variable;
  • Hi Michael! This worked great. I appreciate you taking the time to help me out. Thank you.
    – Ponte
    Jun 21, 2017 at 21:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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