SHARE

Do you wish to display the number of archive months displayed in WordPress? Bloggers in action for years may have observed that their archives list had become too long.

Here, you will learn three easy and effective ways to limit the number of archive months displayed in WordPress:

Method 1

The method is relatively easier than the other two mentioned here. Hence, this one is widely recommended for all users.

Step 1: Install and activate the Collapsing Archives plugin.

Step 2: After activation, visit Appearance » Widgets page. Now add the Collapsing Archives widget to your sidebar.

Step 3: The widget menu will expand for displaying the settings.

The Collapsing Archives widget makes use of JavaScript to collapse archive links into collapsible yearly links. This means your users can click on years for expanding them to view monthly archives. The monthly archives can also be turned collapsible. The users can view post titles underneath.

Step 4: Review the widget settings to precisely suit your requirements.

Step 5: Store your setting by clicking on the ‘Save button.

Step 6: Visit your website and see the widget in action.

Method 2

This method is all about replacing default archives with compact archives. It provides a cleaner alternative to the default archives widget. These are displayed attractively in a very compact more presentable manner.

Step 1: Start by installing and activating the Compact Archives plugin.

Step 2: After activation, visit Appearance » Widgets page. Now add the ‘Compact
Archives’ widget to your sidebar.

Step 3: The step involves working on compact archive settings. The Compact Archives
plugin is available in different three styles, namely; block, initials, or numeric. Choose any one.

Step 4: Store your widget settings by clicking on the save button.

Step 5: Visit your website to see the compact archives in action.

It is possible to use Compact Archives plugin for creating a custom archives page on your website.

Method 3

Here, you need to add code to your WordPress theme files. In case, you are new to coding, hire an experienced freelance web designer & WordPress front-end developer for guidance.

Add the following code to the functions.php file of your theme. Alternatively, you can paste the code to a site-specific plugin.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

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

The above mentioned code will fetch the archives list and restricts it in past six months. Thereafter, it creates a shortcode and allows shortcode in text widgets.
The next step involves reaching out to Appearance » Widgets page. Now add a ‘Text’ widget to your sidebar. Then switch to the text mode. Add your shortcode as stated below:

1
2
3

    [wpb_custom_archives]

Make sure you save your widget settings.

Now visit your website and see your custom archives list in action.

Hope this article has helped you learn some effective ways to limit the number of archive months displayed in WordPress.

4 COMMENTS

LEAVE A REPLY

Please enter your comment!
Please enter your name here