How to limit number of archive months in wordpress.

Tutorial:
Achin Verma

Reviewed by:
Rating:
5
On December 6, 2014
Last modified:January 21, 2016

Summary:

Archives can be gem for your blog visitors navigation.You can make it display specific months by learning how to limit number of archive months in WordPress

Limit number of archive months according to your need

There are many blogs which likes to display archives, this is helpful to organize the posts you published on monthly basis. Archives helps users to easily navigate to the post in a systematic manner. I’ve seen many blogs with a big list of archives that takes a lot of space in the sidebar. I must tell you that the sidebar of your blog is one of the most important part of your blog design.

Limit-number-of-archive-months-in-wordpressIf the archives of your blog takes a lot of space then you are wasting a precious part just for nothing, There are many people who likes to make a their archives shorter, but by default there is no settings by which you can set the number of months for which you want to show your archives.

There are two ways by which you can limit number of archive months in WordPress.

Limit number of archive months in sidebar

You can limit number of archive months in sidebar,with the help of a little change in code.

In order to limit the archive months by numbers, first you have to Dashboard»Appearance»Editor then you have to find the file sidebar.php. Click on it then find the code given below

 <h2>Archives</h2></pre>
<ul> <!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1">php</span> wp_get_archives('type=monthly'); ?--></ul>
<pre>
</ul>

After finding this code replace or edit it to.

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

This limit=9 is the number of months that will be displayed in the archives, you can change the number to your own desired months that you like.

This change of code will help you to limit the number of archive months, this code will work only for the sidebar.

Limit number of archive months for Widgets

To limit number of archive months for widget, you have to go to Dashboard»Appearance»Editor and find the file named functions.php. no all you have to do is add the below code to the file.

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

This code will help you to limit the number of months in widget area, in this limit 6 is the number of months which you can choose according to your need.

Conclusion

These are the ways by which you can limit numbers of archive months by using codes, if you like to add more functionality and designs to your archive then you can even use archive plugins.

Further Read:

 

Achin Verma

I'm Achin Verma writer and creator of zdidit. you can follow me on facebook ,

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

css.php