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

Whenever you add a new post to your site, the WordPress will add an archive list which is attached to the blog. As your website gets older, the archive list will increase as well. The best way to manage this list is by limiting the number of archive months displayed. There are specific methods to perform this action which are uncomplicated as well. Below we mention the complete guide on how you can limit the number of archive months displayed in WordPress.

#1 Manual Method

The first method is the manual method where you will be manually inserting a code into the WordPress core files. Moreover, you need to have the basic coding knowledge to execute this technique.

Step 1

In the first step, you need to connect with your FTP client and open your WordPress directory. Here you can see different folder and files, but you need to find and open the wp-content folder. Now you have to open the Themes> Current theme folder.

Step 2

Once you have opened that folder, you need to find the functions.php file and download it by right-clicking on it. After saving that file on your local system, open it using any text editor and paste the following code into it. Upon pasting the code, you need to head back to your FTP client and upload the file back to your current theme folder.

// Function to get archives list with limited months

function wpb_limit_archives() {

$my_archives = wp_get_archives(array(

‘type’=>’monthly’,

‘limit’=>6,

‘echo’=>0

));

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’);

Step 3

This code will only display the archive list from past six months, but you need to add a shortcode to the text widget to make this code work. You need to navigate to your WordPress admin dashboard and head over to the Appearance> Widgets page. Afterwards, you need to add a new text widget to any of the sidebars. Open the text mode of the widget and paste the following code into it. Make sure to save all the changes and open your website to check whether the method worked or not.

<ul>

[wpb_custom_archives]

</ul>

This was the complete method of limiting the number of archive months manually. Beginner WordPress users may feel this process a bit difficult. If you also feel the same, then here we mention a simpler process that doesn’t require any coding knowledge.

#2 Plugin Method

Step 1

As the name describes, you will be working with a plugin for the same purpose. In the initial stage, you need to install and activate the Collapsing Archives plugin to your site. To install the plugin, you have to open your WordPress admin area and visit the Plugins> Add New page. Search for the plugin and click on the Install Now button. Once the installation completes, you have to click on the activation link, and the plugin will be ready to use.

Step 2

Once you have activated the plugin, you need to head over to your WordPress admin dashboard and navigate to the Appearance> Widgets page. Add the plugin’s widget to any of your sidebars and open its settings page. Here you need to enter the title, decide the collapse character you want to use, the post types and other configurations. After you are done with all the settings, you need to press the Save Changes button.

You can now visit your website to check whether the plugin is working perfectly or not. The configuration options are self-explanatory, so there is no need to explain every part.

If you face any issues with this plugin, then here is another method where you need to install a plugin as well.

#3 Plugin Method Number 2

Step 1

Similar to the previous method, in this process, you need to install a plugin as well. However, you need to install and activate the Compact Archives plugin. You can follow the same method to install and activate the plugin on your site.

Step 2

After successfully activating the plugin, you need to open your WordPress admin dashboard and navigate to the Appearance> Widgets page. Follow the same and add the widget to any of your sidebars. Here enter the title, the transform text and the style. After making all the configurations, you need to press the Save button to keep all the changes. You can now visit your website and see the plugin in action.

Many other plugins can help you in this process. If you don’t want to use the plugins mentioned above, then you can make use of this plugin.

The primary feature of this plugin is to display the archive months in any sidebar of your choice. It can save a lot of space on your sidebar where you can add different widgets for your users. One highlighting feature of this plugin is that it comes with eight different themes which can help you in enhancing the appearance of your website.

It shows all the archive like a calendar where you can choose whether you want to showcase archives in month or years. In addition to that, you can decide which category’s post should be included in the archive list. If you want to customise it further, then you can use different CSS codes to personalise it even further. There are many various features of this plugin, and some of them are theme editor, show monthly post count, theme-specific widgets, support for the custom post type, ability to use custom JavaScript code and much more.

Endnote

Limiting the number of archive months on your posts will save a lot of space on your sidebar where you can place other necessary widgets. We have mentioned multiple methods for the same task. You can choose any of the processes which may be easier for you. Using the plugin is surely the simplest method, but if you are familiar with the website coding, then you can use the manual process as well.