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

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

Last updated on by
Follow WPBeginner on YouTube
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:

<h2>Archives</h2>
<ul>
<?php wp_get_archives('type=monthly'); ?>
</ul>

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:

<h2>Archives</h2>
<ul>
<?php wp_get_archives('type=monthly&limit=6'); ?>
</ul>

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 lovers 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 »
  • http://www.technicacreative.co.uk Dave Jones

    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.

    • http://www.wpbeginner.com Editorial Staff

      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.