Forums

Remove Post Count Parentheses From Widget (5 posts)

  1. norbiu
    Member
    Posted 2 years ago #

    When I insert the Archives widget and check the "Show Post Counts", it wraps the number in parentheses. Is there any way to edit that within functions.php without modifying the core files? Thanks!

  2. st3vi3
    Member
    Posted 1 year ago #

    would love to know this too - i have searched and search

    i managed to do this with the wp_categories_list in my child theme as follows:

    // remove parentheses from category list and add span class to post count
    function categories_postcount_filter ($variable) {
    $variable = str_replace('(', '<span class="post-count"> ', $variable);
    $variable = str_replace(')', ' </span>', $variable);
       return $variable;
    }
    add_filter('wp_list_categories','categories_postcount_filter');

    alas replacing wp_list_categories with wp_get_archives has no impact.

    Anyone any ideas?

  3. alchymyth
    The Sweeper
    Posted 1 year ago #

    archives are a bit different:

    add_filter('get_archives_link', 'archive_count_no_brackets');
    function archive_count_no_brackets($links) {
    $links = str_replace('</a>&nbsp;(', '</a>&nbsp;', $links);
    $links = str_replace(')', '', $links);
    return $links;
    }
  4. st3vi3
    Member
    Posted 1 year ago #

    alchymyth
    THANK YOU SO MUCH!

    hmmm *wonders why it is $links and not $variable*
    - how does one know what parameter to pick?!

    php nube here :(

  5. alchymyth
    The Sweeper
    Posted 1 year ago #

    hmmm *wonders why it is $links and not $variable*
    - how does one know what parameter to pick?!

    you can make one up - as long as it does not conflict with one of the global variables used by the core of wordpress ;-)

Topic Closed

This topic has been closed to new replies.

About this Topic