How to reduce the number of months in a wordpress archive?


Want to reduce the number of months displayed in the archive? Such a desire may well arise if you have a website for several years and the list of archived months is too cumbersome. In this article, I’ll show you how to limit the number of archived months displayed in WordPress.

How to limit the number of archived months

Method Number 1. Reduce The Number Of Months In The Archive Using A Special Plugin

This method is the simplest and preferred for all users.
To start the task, download and activate the Collapsing Archives plugin. If you have any difficulties with this, then read my step-by-step instructions on how to install WordPress plugins .
After activation, go to the Appearance »Widgets page   and add the CollapsingArchives widget to the sidebar.
Adding the Collapsing Archives widget to the sidebar
Extend the widget menu to see all the settings.
The Collapsing Archives widget uses the JavaScript language to convert archived links to expandable annual links. This means that your users can click on the years, and in front of them appears a breakdown of the archive by month. In addition, you can even make monthly archives expandable and show users the titles of entries for that month.
In general, configure everything as you would like - click the "Save" button. Visit the site to check how everything is displayed.
Now archives are opened with a list of years

METHOD NO. 2. REPLACE THE STANDARD ARCHIVE WITH THE ARCHIVE FROM THE COMPACT ARCHIVES PLUGIN

This is a pretty good alternative to the standard archive widget, as The Compact Archives plugin displays the archive more compactly and presentably.
To do this, install and activate the Compact Archives plugin.
After activation, go to the Appearance »Widgets page   and add the“ Compact Archives ”widget to the sidebar.
Adding a Compact Archives plugin widget to the sidebar
The plugin provides 3 styles of archive design: block, initial, digital.
Select the necessary settings and do not forget to click on the “Save” button.
Go to the site and see how the archive now looks.
Alphabetical display of months by years with Compact Archives
This plugin can also be used to create custom archive pages on the site.

Method No. 3. Manually Reduce The Number Of Months Displayed In The Wordpress Archive

This method requires adding code to WordPress theme files.
Paste the following code in the functions.php theme file or in the site-specific plugin.
// 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');
1
// 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');
This code will extract all archived months and leave only the last 6 months displayed. Then he will create a shortcode and include it in the text widgets.
Now go to the Appearance »Widgets page and add the“ Text ”widget to the sidebar. Switch to text mode and add the resulting shortcode as follows:
<ul>
[wpb_custom_archives]
</ul>
1
<ul>
[wpb_custom_archives]
</ul>
Remember to save the changes.
Now you can go to the site and see how your user archive looks.
That's all. I hope this article helped you figure out how to reduce the number of months displayed in the WordPress archive. You may also find it helpful to learn about the most useful tricks with the htaccess file .
For more information visit our website Digital Marketing Services in UAE

Comments

Popular posts from this blog

How to change the url in the wordpress site search form

The Strategies & Successes of Paid Advertising Campaign

Compromising Information in the Fight against Competitors by the Method of Black Pr Campaign