Beginner's Guide for WordPress - Start your WordPress Blog in minutes.
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
WordPress Plugins
View all Guides

How to Limit the Number of Archive Months Displayed in WordPress?

Last updated on by
Special WordPress Hosting offer for WPBeginner Readers
How to Limit the Number of Archive Months Displayed in WordPress?

If you visit some blogs, their sidebar is filled with archive months. There are some people who like to have archive links in the sidebar because they want their user to browse easily, and there are some who just want to show how old their blog really is. But to the majority of the users, having 26 months listed in the sidebar is a waste of space. Therefore we will show you how to limit the number of archive months displayed in WordPress.

In most themes, you will see the code in sidebar.php to be some what like this:

<?php wp_get_archives('type=monthly'); ?>

These codes are the default ones that come with many theme. It works out perfectly fine for the first few months, but as your blog gets older, it becomes a clutter in the sidebar. So you should change it to the following codes:

<?php wp_get_archives('type=monthly&limit=6'); ?>

You can change the number 6 to the number of your choice. This is a perfect compromise for those who want to help users browse few older months, but not have clutter. In our next tutorials we will show you how you can make yourself a custom Archive page for WordPress.

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi. Page maintained by Syed Balkhi.

WPBeginner's Video Icon
Our HD-Quality tutorial videos for WordPress Beginners will teach you how to use WordPress to create and manage your own website in about an hour. Get started now »


  1. Sanders F. Cruz says:

    Thanks Bro!, this is my code :)


    Note: the content of class css “archive-archive1” is:

    /* Style New Archive */
    font-size: 12px !important;
    font-size: 0.785714286rem;
    line-height: 2.181818182;
    color: #f2f2f2;

  2. Dave Jones says:

    I don’t think this will work if your theme is widget enabled (most modern themes are). In general changing sidebar.php is only useful for older, non-widget enabled themes.

    Instead, you should use something like Breukie’s Archive Widget which allows you to set parameters like type and limit in the options.

    • Editorial Staff says:

      This is for those who do not want to have plugins. Yes Breukie’s Archive Widget is a good choice who want to use a lot of plugins.

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 comment policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.