X

Limit Archives Widget to Display Only 12 Months

Snippets by IsItWP

Do you want to change the settings of the default archives widget? While there’s probably a plugin for this, we have created a quick code snippet that you can use to limit archives widget to display only 12 months in WordPress.

Instructions:

All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:

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

If you want to create a dropdown of the archives and limit it to 12 months, then simply add this code snippet to the functions.php file or site-specific plugin.

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

add_filter( 'widget_archives_dropdown_args', 'my_limit_archives' );

Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly copy / paste code snippets in WordPress, so you don’t accidentally break your site.

If you liked this code snippet, please consider checking out our other articles on the site like: How to increase maximum file upload size in WordPress and 23 effective tips to get more email subscribers.

Comments   Leave a Reply

  1. Hi, nice snippet.
    Can you just tell me how is it possible to know all vars in the $args parameter?
    I would like to use this code to exclude one category from the archives but I can’t find a documentation page explaining how to use filter args in general.
    Thanks 😉

  2. Adrian Robertson April 7, 2013 at 10:24 pm

    Thanks! Tried a few other solutions, this is the only one that worked for me. Appreciate it

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!