• Hi,

    I can see this question has been asked many times before, but what I want is a variation on code that I know works.

    Over here there is a solution to get the posts counts next to the category titles in the default categories widget.

    add_filter('wp_list_categories', 'cat_count_inline');
    function cat_count_inline($links) {
    $links = str_replace('</a> (', ' (', $links);
    $links = str_replace(')', ')</a>', $links);
    return $links;
    }

    What I would like is a variation on that solution to incorperate a span class for positioning purposes. In terms of HTML/CSS. I need the output the same as this one for woocommerce product category listing:

    <li class="cat-item cat-item-24">
    <a href="https://domain.com/product-category/cleaning/">Cleaning</a>
    <span class="count">(0)</span>
    </li>

    It’s that <span class=”count”> that I need.

    Regards,
    Matt

Viewing 1 replies (of 1 total)
  • try (untested):

    add_filter('wp_list_categories', 'cat_count_inline');
    function cat_count_inline($links) {
    $links = str_replace('</a> (', '</a><span class="count">(', $links);
    $links = str_replace(')', ')</span>', $links);
    return $links;
    }
Viewing 1 replies (of 1 total)
  • The topic ‘Post Counts On One Line For Categories Widget With Span’ is closed to new replies.