Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

The default Archive widget display monthly archives in a dropdown.

I would like to limit the number of months to 12 (in dropdown).

What filter I should apply in my functions.php?

I tried this, but it gives me parsed error:

add_filter('WP_Widget_Archives','set_number_months');
function set_number_months($args) {
$args = array('number'    => 12);
return $args;
}

I also tried with wp_get_archives but same parsed error

share|improve this question

1 Answer 1

up vote 4 down vote accepted

Use the widget_archives_args filter to add the archives limit.

function my_limit_archives( $args ) {
    $args['limit'] = 12;
    return $args;
}
add_filter( 'widget_archives_args', 'my_limit_archives' );

And to limit the number of months in Archives widget dropdown use the following drop down filter.

add_filter( 'widget_archives_dropdown_args', 'my_limit_archives' );
share|improve this answer
    
thanks. will try and let you know –  Tara Jun 15 '11 at 0:16
    
I tried, it did not limit to 12. Any more ideas? thanks –  Tara Jun 15 '11 at 2:12
    
Sorry I missed the dropdown part. I have updated my answer with the dropdown filter too. –  Hameedullah Khan Jun 15 '11 at 5:03
    
thanks, it worked. –  Tara Jun 15 '11 at 15:48
    
+1 how to add HTML below the archives widget? –  Brad Dalton Mar 1 at 5:26

Your Answer

 
discard

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

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