WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I wrap the "show_post_count" between a div? (from the wp_get_archives())
Do I need to edit the function for that?

Or could I do something like this with pseudo css?

<div class="post_count">
    <a href="http://www.finsens.salescaredev.nl/2012/03" title="March 2012">March 2012</a>&nbsp;(1)


.post_count a:after (all the content in the div and after the .post_count){
 float: right;
share|improve this question
up vote 2 down vote accepted

You can style the post count differently via CSS with the given markup. It’s not very practical but by making use of the cascading nature of CSS, you could do this:

.post_count { /* styles for the post count number in parenthesis */ }
.post_count a { /* styles for the link, be sure to override properties from the line above if needed */ }

Whatever you do, don’t edit the wp_get_archives() function directly. You will lose your changes when WP gets updated. That function does not provide any useful filters for doing what you want.

If you want to wrap the post count in an additional HTML element, try this approach. By returning the output of wp_get_archives() you have the option to tweak the markup and target the count directly via CSS (.post_count .count):

// Generate the default list
$html = wp_get_archives( array(
    'show_post_count' => true,
    'echo' => false,
) );
// Wrap the post count in a span element
$html = preg_replace( '~(&nbsp;)(\(\d++\))~', '$1<span class="count">$2</span>', $html );
// Output the result
echo $html;

Note: I am well aware that parsing HTML using regular expressions is considered evil. No need to remind me about that. I’m all ears for better solutions.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.