You might have seen a lot of blogs with their sidebar stuffed with archive months. Some folks like to have archive links in the sidebar for the sake of UX, and then, there are a few who just are interested in showing off how old their blog is. To the most of us, having 16 months listed in the sidebar is a terrible waste of space. Let us show you how you can limit the number of archives displayed in WordPress.
In most of the themes, you will find a code snippet in the sidebar.php very similar to this:
&lt;h2&gt;Archives&lt;/h2&gt; &lt;ul&gt; &lt;?php wp_get_archives('type=monthly'); ?&gt; &lt;/ul&gt;
Let’s Limit the Number of Archive Months
This code snippet comes built-in with many themes. It works fine for the first few months, but as your blog gets older, it adds to the clutter in your sidebar. Replace it with the following code snippet:
&lt;h2&gt;Archives&lt;/h2&gt; &lt;ul&gt; &lt;?php wp_get_archives('type=monthly&amp;limit=7'); ?&gt; &lt;/ul&gt;
Feel free to change the monthly limit from 7 to whatever you like. This approach helps users browse older month archives, without all that clutter. A win-win for everyone, isn’t it?