Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
25 Million+
Websites using our plugins
Years of WordPress experience
WordPress tutorials
by experts

How to Limit the Number of Archive Months Displayed in WordPress

Editorial Note: We earn a commission from partner links on WPBeginner. Commissions do not affect our editors' opinions or evaluations. Learn more about Editorial Process.

Do you want to display the number of archive months displayed in WordPress?

If you have been blogging for years, you will notice that your archives list will become too long.

In this article, we will show you how to limit the number of archive months displayed in WordPress.

How to limit number of archive months in WordPress

Video Tutorial

Subscribe to WPBeginner

If you don’t like the video or need more instructions, then continue reading.

Method 1. Limit Number of Archive Months with Plugin

This method is easier and it is recommended for all users.

The first thing you need to do is install and activate the Collapsing Archives plugin. For more details, see our step by step guide on how to install a WordPress plugin.

Upon activation, you need to visit Appearance » Widgets page and add the Collapsing Archives widget to your sidebar.

Collapse archives

The widget menu will expand to show its settings.

The Collapsing Archives widget uses JavaScript to collapse your archive links into collapsible yearly links. Your users can click on years to expand them to view monthly archives. You can even make monthly archives collapsible and allow users to see post titles underneath.

Review the widget settings to suit your needs and then click on the ‘Save’ button to store your settings.

You can now visit your website to see the widget in action.

Collapsing archives

Method 2. Replace Default Archives with Compact Archives

This method provides a cleaner alternative to the default archives widget by beautifully displaying them in a compact more presentable way.

First, you need to install and activate the Compact Archives plugin. For more details, see our step by step guide on how to install a WordPress plugin.

Upon activation, you need to visit Appearance » Widgets page and add the ‘Compact Archives’ widget to your sidebar.

Compact Archives settings

Compact Archives plugin comes in three styles. You can choose from block, initials, or numeric.

Don’t forget to click on the ‘Save’ button to store your widget settings.

You can now visit your website to see the compact archives in action.

Compact Archives preview

You can also use Compact Archives plugin to create a custom archives page on your site.

For more details see our guide on how to create compact archives in WordPress.

Method 3. Manually Limit Number of Archive Months in WordPress

This method requires you to add code to your WordPress theme files. If you haven’t done this before, then take a look at our guide on how to copy and paste code in WordPress.

You will need to add the following code to your theme’s functions.php file or a code snippets plugin.

// Function to get archives list with limited months
function wpb_limit_archives() { 
$my_archives = wp_get_archives(array(
return $my_archives; 
// Create a shortcode
add_shortcode('wpb_custom_archives', 'wpb_limit_archives'); 
// Enable shortcode execution in text widget
add_filter('widget_text', 'do_shortcode'); 

We recommending adding code using WPCode, the best WordPress code snippets plugin. It allows you to safely add custom code in WordPress, without editing your functions.php file.

The first thing you need to do is install and activate the free WPCode plugin. If you need help, see this guide on how to install a WordPress plugin.

Once you’ve activated the plugin, go to Code Snippets » + Add Snippet from the WordPress dashboard.

Then, hover your mouse over the ‘Add Your Custom Code (New Snippet)’ option and click the ‘Use snippet’ button.

Add a new custom code snippet in WPCode

From here, you can add a title for your snippet, which can be anything to help you remember what the code is for.

Next, paste the code from above into the ‘Code Preview’ box and select ‘PHP Snippet’ as the code type from the dropdown menu.

Paste the code snippet into WPCode

After that, simply toggle the switch from ‘Inactive’ to ‘Active’ and click the ‘Save Snippet’ button.

Activate and save your custom code snippet

This code fetches the archives list and limits it to past 6 months only. It then creates a shortcode and enables shortcode in text widgets.

You can now go to Appearance » Widgets page and add a ‘Text’ widget to your sidebar. Switch to the text mode and add your shortcode like this:


Don’t forget to save your widget settings.

You can now visit your website to see your custom archives list in action.

That’s all, we hope this article helped you learn how to limit the number of archive months displayed in WordPress. You may also want to see our list of these most useful tricks for the WordPress functions file and our guide on how to remove the archive page in WordPress.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us. Here's our editorial process.

Editorial Staff

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit - a collection of WordPress related products and resources that every professional should have!

Reader Interactions

10 CommentsLeave a Reply

  1. Syed Balkhi says

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. Jiří Vaněk says

    I have never used an archive on my site. Then I read one of your articles, where I read that it should be on the website. But that was a problem because it was too long. This snippet solved the whole problem brilliantly. Thanks

  3. Jenny says

    I used this code and it worked perfectly.
    But the problem is that whenever I select a month, it takes me to the homepage.

    • WPBeginner Support says

      It would depend on the method you are using. If you are using a plugin then you would want to reach out using the plugin’s support forum


  4. Gaz says


    I would like to ask how can I show the amount of posts next to the month in the archive list in the footer?


    May 2018 (5)

    I put the above code on the site however I would like to show how many posts have been published each month as well.



  5. Gaelyn says

    Seems rather stupid to have to add plugins to stop something I didn’t ask for in the first place. How about just on/off. No reason to load all the archives.

  6. Stegemüller says

    Hi there,

    I simply love your site! I have been using WP for 10 years, but finally I am beginning to learn how to go backend and manipulate. Great fun and very useful.

    To day I followed your advise about limiting the number of archives, and I used “Method 3. Manually Limit Number of Archive Months in WordPress” – It works great.

    I just have one question: Is it possible to make the first letter a capital letter? I.e.: January not january, February not february and so on.

    • WPBeginner Support says

      Hi Stegemüller,

      By default, it should display month names starting with capital letter. If you are using WordPress in another language, then it is possible that localization files has month names in small letters. If you can confirm and report it, then translators would be able to fix that.

      As a temporary fix you can use CSS. Wrap your shortcode around a div

      <div class="capsfix">[wpb_custom_archives]</div>

      Then add this custom CSS:

      .capsfix li {


Leave A Reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.