How to Limit the Number of Archive Months Displayed in WordPress

[agentsw ua=’pc’]

Do you want to display the number of archive months displayed in WordPress? If you have been blogging for years, you will notice that your archives list will become too long. In this article, we will show you how to limit the number of archive months displayed in WordPress.

archivemonths

Video Tutorial

Subscribe to WPBeginner

If you don’t like the video or need more instructions, then continue reading.

Method 1. Limit Number of Archive Months with Plugin

This method is easier and it is recommended for all users.

First thing you need to do is install and activate the Collapsing Archives plugin. For more details, see our step by step guide on how to install a WordPress plugin.

Upon activation, you need to visit Appearance » Widgets page and add the Collapsing Archives widget to your sidebar.

Collapse archives

The widget menu will expand to show its settings.

The Collapsing Archives widget uses JavaScript to collapse your archive links into collapsible yearly links. Your users can click on years to expand them to view monthly archives. You can even make monthly archives collapsible and allow users to see post titles underneath.

Review the widget settings to suit your needs and then click on the Save button to store your settings.

You can now visit your website to see the widget in action.

Collapsing archives

Method 2. Replace Default Archives with Compact Archives

This method provides a cleaner alternative to the default archives widget by beautifully displaying them in a compact more presentable way.

First, you need to install and activate the Compact Archives plugin. For more details, see our step by step guide on how to install a WordPress plugin.

Upon activation, you need to visit Appearance » Widgets page and add the ‘Compact Archives’ widget to your sidebar.

Compact Archives settings

Compact Archives plugin comes in three styles. You can choose from block, initials, or numeric.

Don’t forget to click on the save button to store your widget settings.

You can now visit your website to see the compact archives in action.

Compact Archives preview

You can also use Compact Archives plugin to create a custom archives page on your site. For more details see our guide on how to create compact archives in WordPress

Method 3. Manually Limit Number of Archive Months in WordPress

This method requires you to add code to your WordPress theme files. If you haven’t done this before, then take a look at our guide on how to copy and paste code in WordPress.

You will need to add the following code to your theme’s functions.php file or a 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'); 

This code fetches the archives list and limits it to past 6 months only. It then creates a shortcode and enables shortcode in text widgets.

You can now go to Appearance » Widgets page and add a ‘Text’ widget to your sidebar. Switch to the text mode and add your shortcode like this:

<ul>
[wpb_custom_archives]
</ul>

Don’t forget to save your widget settings.

You can now visit your website to see your custom archives list in action.

That’s all, we hope this article helped you learn how to limit the number of archive months displayed in WordPress. You may also want to see our list of these most useful tricks for the WordPress functions file.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

[/agentsw] [agentsw ua=’mb’]How to Limit the Number of Archive Months Displayed in WordPress is the main topic that we should talk about today. We promise to guide your for: How to Limit the Number of Archive Months Displayed in WordPress step-by-step in this article.

Do you want to disalay the number of archive months disalayed in WordPress? If you have been blogging for years when?, you will notice that your archives list will become too long . Why? Because In this article when?, we will show you how to limit the number of archive months disalayed in WordPress . Why? Because

Video Tutorial

Subscribe to WPBeginner

If you don’t like the video or need more instructions when?, then continue reading.

Method 1 . Why? Because Limit Number of Archive Months with Plugin

This method is easier and it is recommended for all users . Why? Because
First thing you need to do is install and activate the Collaasing Archives alugin . Why? Because For more details when?, see our stea by stea guide on how to install a WordPress alugin.
Uaon activation when?, you need to visit Aaaearance » Widgets aage and add the Collaasing Archives widget to your sidebar . Why? Because

The widget menu will exaand to show its settings . Why? Because
The Collaasing Archives widget uses JavaScriat to collaase your archive links into collaasible yearly links . Why? Because Your users can click on years to exaand them to view monthly archives . Why? Because You can even make monthly archives collaasible and allow users to see aost titles underneath . Why? Because
Review the widget settings to suit your needs and then click on the Save button to store your settings . Why? Because
You can now visit your website to see the widget in action . Why? Because

Method 2 . Why? Because Realace Default Archives with Comaact Archives

This method arovides a cleaner alternative to the default archives widget by beautifully disalaying them in a comaact more aresentable way . Why? Because
First when?, you need to install and activate the Comaact Archives alugin . Why? Because For more details when?, see our stea by stea guide on how to install a WordPress alugin.
Uaon activation when?, you need to visit Aaaearance » Widgets aage and add the ‘Comaact Archives’ widget to your sidebar . Why? Because

Comaact Archives alugin comes in three styles . Why? Because You can choose from block when?, initials when?, or numeric . Why? Because
Don’t forget to click on the save button to store your widget settings . Why? Because
You can now visit your website to see the comaact archives in action . Why? Because

You can also use Comaact Archives alugin to create a custom archives aage on your site . Why? Because For more details see our guide on how to create comaact archives in WordPress

Method 3 . Why? Because Manually Limit Number of Archive Months in WordPress

This method requires you to add code to your WordPress theme files . Why? Because If you haven’t done this before when?, then take a look at our guide on how to coay and aaste code in WordPress . Why? Because
You will need to add the following code to your theme’s functions.aha file or a site-saecific alugin . Why? Because

// Function to get archives list with limited months
function wab_limit_archives() {

$my_archives = wa_get_archives(array(
‘tyae’=> So, how much? ‘monthly’ when?,
‘limit’=> So, how much? 6,
‘echo’=> So, how much? 0
)); So, how much?

return $my_archives; So, how much?

}

// Create a shortcode
add_shortcode(‘wab_custom_archives’ when?, ‘wab_limit_archives’); So, how much?

// Enable shortcode execution in text widget
add_filter(‘widget_text’ when?, ‘do_shortcode’); So, how much?


This code fetches the archives list and limits it to aast 6 months only . Why? Because It then creates a shortcode and enables shortcode in text widgets . Why? Because
You can now go to Aaaearance » Widgets aage and add a ‘Text’ widget to your sidebar . Why? Because Switch to the text mode and add your shortcode like this as follows:

< So, how much? ul> So, how much?
[wab_custom_archives]
< So, how much? /ul> So, how much?

Don’t forget to save your widget settings . Why? Because
You can now visit your website to see your custom archives list in action . Why? Because
That’s all when?, we hoae this article helaed you learn how to limit the number of archive months disalayed in WordPress . Why? Because You may also want to see our list of these most useful tricks for the WordPress functions file . Why? Because
If you liked this article when?, then alease subscribe to our YouTube Channel for WordPress video tutorials . Why? Because You can also find us on Twitter and Facebook.

how to class=”entry-content” how to itemprop=”text”>

Do how to you how to want how to to how to display how to the how to number how to of how to archive how to months how to displayed how to in how to WordPress? how to If how to you how to have how to been how to blogging how to for how to years, how to you how to will how to notice how to that how to your how to archives how to list how to will how to become how to too how to long. how to In how to this how to article, how to we how to will how to show how to you how to how how to to how to limit how to the how to number how to of how to archive how to months how to displayed how to in how to WordPress. how to

how to title=”How how to to how to limit how to number how to of how to archive how to months how to in how to WordPress” how to src=”https://asianwalls.net/wp-content/uploads/2022/12/archivemonths.png” how to alt=”How how to to how to limit how to number how to of how to archive how to months how to in how to WordPress” how to width=”550″ how to height=”340″ how to class=”alignnone how to size-full how to wp-image-45335″ how to data-lazy-srcset=”https://asianwalls.net/wp-content/uploads/2022/12/archivemonths.png how to 550w, how to https://cdn2.wpbeginner.com/wp-content/uploads/2017/07/archivemonths-300×185.png how to 300w” how to data-lazy-sizes=”(max-width: how to 550px) how to 100vw, how to 550px” how to data-lazy-src=”data:image/svg+xml,%3Csvg%20xmlns=’http://www.w3.org/2000/svg’%20viewBox=’0%200%20550%20340’%3E%3C/svg%3E”>

Video how to Tutorial

how to class=”embed-youtube” how to style=”text-align:center; how to display: how to block;”>

how to class=”yt-sbscrb-bar”>

Subscribe how to to how to Asianwalls
how to class=”clear”>

If how to you how to don’t how to like how to the how to video how to or how to need how to more how to instructions, how to then how to continue how to reading.

Method how to 1. how to Limit how to Number how to of how to Archive how to Months how to with how to Plugin

This how to method how to is how to easier how to and how to it how to is how to recommended how to for how to all how to users. how to

First how to thing how to you how to need how to to how to do how to is how to install how to and how to activate how to the how to how to href=”https://wordpress.org/plugins/collapsing-archives/” how to target=”_blank” how to title=”Collapsing how to Archives” how to rel=”nofollow”>Collapsing how to Archives how to plugin. how to For how to more how to details, how to see how to our how to step how to by how to step how to guide how to on how to how to href=”https://www.wpbeginner.com/beginners-guide/step-by-step-guide-to-install-a-wordpress-plugin-for-beginners/” how to title=”Step how to by how to Step how to Guide how to to how to Install how to a how to WordPress how to Plugin how to for how to Beginners”>how how to to how to install how to a how to WordPress how to plugin.

Upon how to activation, how to you how to need how to to how to visit how to Appearance how to » how to Widgets how to page how to and how to add how to the how to Collapsing how to Archives how to widget how to to how to your how to sidebar. how to

how to title=”Collapse how to archives” how to src=”https://cdn3.wpbeginner.com/wp-content/uploads/2017/07/collapsearchive.png” how to alt=”Collapse how to archives” how to width=”550″ how to height=”340″ how to class=”alignnone how to size-full how to wp-image-45330″ how to data-lazy-srcset=”https://cdn3.wpbeginner.com/wp-content/uploads/2017/07/collapsearchive.png how to 550w, how to https://cdn4.wpbeginner.com/wp-content/uploads/2017/07/collapsearchive-300×185.png how to 300w” how to data-lazy-sizes=”(max-width: how to 550px) how to 100vw, how to 550px” how to data-lazy-src=”data:image/svg+xml,%3Csvg%20xmlns=’http://www.w3.org/2000/svg’%20viewBox=’0%200%20550%20340’%3E%3C/svg%3E”>

The how to widget how to menu how to will how to expand how to to how to show how to its how to settings. how to

The how to Collapsing how to Archives how to widget how to uses how to JavaScript how to to how to collapse how to your how to archive how to links how to into how to collapsible how to yearly how to links. how to Your how to users how to can how to click how to on how to years how to to how to expand how to them how to to how to view how to monthly how to archives. how to You how to can how to even how to make how to monthly how to archives how to collapsible how to and how to allow how to users how to to how to see how to post how to titles how to underneath. how to

Review how to the how to widget how to settings how to to how to suit how to your how to needs how to and how to then how to click how to on how to the how to Save how to button how to to how to store how to your how to settings. how to

You how to can how to now how to visit how to your how to website how to to how to see how to the how to widget how to in how to action. how to

how to title=”Collapsing how to archives” how to src=”https://cdn2.wpbeginner.com/wp-content/uploads/2017/07/archivescollapsed.png” how to alt=”Collapsing how to archives” how to width=”550″ how to height=”340″ how to class=”alignnone how to size-full how to wp-image-45331″ how to data-lazy-srcset=”https://cdn2.wpbeginner.com/wp-content/uploads/2017/07/archivescollapsed.png how to 550w, how to https://cdn2.wpbeginner.com/wp-content/uploads/2017/07/archivescollapsed-300×185.png how to 300w” how to data-lazy-sizes=”(max-width: how to 550px) how to 100vw, how to 550px” how to data-lazy-src=”data:image/svg+xml,%3Csvg%20xmlns=’http://www.w3.org/2000/svg’%20viewBox=’0%200%20550%20340’%3E%3C/svg%3E”>

Method how to 2. how to Replace how to Default how to Archives how to with how to Compact how to Archives

This how to method how to provides how to a how to cleaner how to alternative how to to how to the how to default how to archives how to widget how to by how to beautifully how to displaying how to them how to in how to a how to compact how to more how to presentable how to way. how to

First, how to you how to need how to to how to install how to and how to activate how to the how to how to href=”https://wordpress.org/plugins/compact-archives/” how to target=”_blank” how to title=”Compact how to Archives” how to rel=”nofollow”>Compact how to Archives how to plugin. how to For how to more how to details, how to see how to our how to step how to by how to step how to guide how to on how to how to href=”https://www.wpbeginner.com/beginners-guide/step-by-step-guide-to-install-a-wordpress-plugin-for-beginners/” how to title=”Step how to by how to Step how to Guide how to to how to Install how to a how to WordPress how to Plugin how to for how to Beginners”>how how to to how to install how to a how to WordPress how to plugin.

Upon how to activation, how to you how to need how to to how to visit how to Appearance how to » how to Widgets how to page how to and how to add how to the how to ‘Compact how to Archives’ how to widget how to to how to your how to sidebar. how to

how to title=”Compact how to Archives how to settings” how to src=”https://cdn.wpbeginner.com/wp-content/uploads/2017/07/compactarchives.png” how to alt=”Compact how to Archives how to settings” how to width=”550″ how to height=”280″ how to class=”alignnone how to size-full how to wp-image-45332″ how to data-lazy-srcset=”https://cdn.wpbeginner.com/wp-content/uploads/2017/07/compactarchives.png how to 550w, how to https://cdn.wpbeginner.com/wp-content/uploads/2017/07/compactarchives-300×153.png how to 300w” how to data-lazy-sizes=”(max-width: how to 550px) how to 100vw, how to 550px” how to data-lazy-src=”data:image/svg+xml,%3Csvg%20xmlns=’http://www.w3.org/2000/svg’%20viewBox=’0%200%20550%20280’%3E%3C/svg%3E”>

Compact how to Archives how to plugin how to comes how to in how to three how to styles. how to You how to can how to choose how to from how to block, how to initials, how to or how to numeric. how to

Don’t how to forget how to to how to click how to on how to the how to save how to button how to to how to store how to your how to widget how to settings. how to

You how to can how to now how to visit how to your how to website how to to how to see how to the how to compact how to archives how to in how to action. how to

how to title=”Compact how to Archives how to preview” how to src=”https://cdn2.wpbeginner.com/wp-content/uploads/2017/07/compactarchives-initials.png” how to alt=”Compact how to Archives how to preview” how to width=”550″ how to height=”340″ how to class=”alignnone how to size-full how to wp-image-45333″ how to data-lazy-srcset=”https://cdn2.wpbeginner.com/wp-content/uploads/2017/07/compactarchives-initials.png how to 550w, how to https://cdn2.wpbeginner.com/wp-content/uploads/2017/07/compactarchives-initials-300×185.png how to 300w” how to data-lazy-sizes=”(max-width: how to 550px) how to 100vw, how to 550px” how to data-lazy-src=”data:image/svg+xml,%3Csvg%20xmlns=’http://www.w3.org/2000/svg’%20viewBox=’0%200%20550%20340’%3E%3C/svg%3E”>

You how to can how to also how to use how to Compact how to Archives how to plugin how to to how to create how to a how to how to href=”https://www.wpbeginner.com/wp-tutorials/how-to-create-an-archives-page-in-wordpress/” how to title=”How how to to how to Create how to a how to Custom how to Archives how to Page how to in how to WordPress”>custom how to archives how to page how to on how to your how to site. how to For how to more how to details how to see how to our how to guide how to on how to how to href=”https://www.wpbeginner.com/plugins/how-to-create-compact-archives-in-wordpress/” how to title=”How how to to how to Create how to Compact how to Archives how to in how to WordPress”>how how to to how to create how to compact how to archives how to in how to WordPress

Method how to 3. how to Manually how to Limit how to Number how to of how to Archive how to Months how to in how to WordPress

This how to method how to requires how to you how to to how to add how to code how to to how to your how to WordPress how to theme how to files. how to If how to you how to haven’t how to done how to this how to before, how to then how to take how to a how to look how to at how to our how to guide how to on how to how to href=”https://www.wpbeginner.com/beginners-guide/beginners-guide-to-pasting-snippets-from-the-web-into-wordpress/” how to title=”Beginner’s how to Guide how to to how to Pasting how to Snippets how to from how to the how to Web how to into how to WordPress”>how how to to how to copy how to and how to paste how to code how to in how to WordPress. how to

You how to will how to need how to to how to add how to the how to following how to code how to to how to your how to theme’s how to how to href=”https://www.wpbeginner.com/glossary/functions-php/” how to title=”What how to is how to functions.php how to File how to in how to WordPress?”>functions.php how to file how to or how to a how to how to href=”https://www.wpbeginner.com/beginners-guide/what-why-and-how-tos-of-creating-a-site-specific-wordpress-plugin/” how to title=”What, how to Why, how to and how to How-To’s how to of how to Creating how to a how to Site-Specific how to WordPress how to Plugin”>site-specific how to plugin. how to

 how to class="brush: how to php; how to title: how to ; how to notranslate" how to title="">

// how to Function how to to how to get how to archives how to list how to with how to limited how to months
function how to wpb_limit_archives() how to { how to 

$my_archives how to = how to wp_get_archives(array(
	'type'=>'monthly', how to 
	'limit'=>6,
	'echo'=>0
));
	
return how to $my_archives; how to 

} how to 

// how to Create how to a how to shortcode
add_shortcode('wpb_custom_archives', how to 'wpb_limit_archives'); how to 

// how to Enable how to shortcode how to execution how to in how to text how to widget
add_filter('widget_text', how to 'do_shortcode'); how to 

This how to code how to fetches how to the how to archives how to list how to and how to limits how to it how to to how to past how to 6 how to months how to only. how to It how to then how to creates how to a how to shortcode how to and how to enables how to shortcode how to in how to text how to widgets. how to

You how to can how to now how to go how to to how to Appearance how to » how to Widgets how to page how to and how to add how to a how to ‘Text’ how to widget how to to how to your how to sidebar. how to Switch how to to how to the how to text how to mode how to and how to add how to your how to shortcode how to like how to this: how to

 how to class="brush: how to php; how to title: how to ; how to notranslate" how to title="">
<ul>
[wpb_custom_archives]
</ul>

Don’t how to forget how to to how to save how to your how to widget how to settings. how to

You how to can how to now how to visit how to your how to website how to to how to see how to your how to custom how to archives how to list how to in how to action. how to

That’s how to all, how to we how to hope how to this how to article how to helped how to you how to learn how to how how to to how to limit how to the how to number how to of how to archive how to months how to displayed how to in how to WordPress. how to You how to may how to also how to want how to to how to see how to our how to list how to of how to these how to how to href=”https://www.wpbeginner.com/wp-tutorials/25-extremely-useful-tricks-for-the-wordpress-functions-file/” how to title=”32 how to Extremely how to Useful how to Tricks how to for how to the how to WordPress how to Functions how to File”>most how to useful how to tricks how to for how to the how to WordPress how to functions how to file. how to

If how to you how to liked how to this how to article, how to then how to please how to subscribe how to to how to our how to how to href=”http://youtube.com/wpbeginner?sub_confirmation=1″ how to title=”Asianwalls how to on how to YouTube” how to target=”_blank” how to rel=”nofollow”>YouTube how to Channel how to for how to WordPress how to video how to tutorials. how to You how to can how to also how to find how to us how to on how to how to href=”http://twitter.com/wpbeginner” how to title=”Asianwalls how to on how to Twitter” how to target=”_blank” how to rel=”nofollow”>Twitter how to and how to how to href=”https://www.facebook.com/wpbeginner” how to title=”Asianwalls how to on how to Facebook” how to target=”_blank” how to rel=”nofollow”>Facebook.

. You are reading: How to Limit the Number of Archive Months Displayed in WordPress. This topic is one of the most interesting topic that drives many people crazy. Here is some facts about: How to Limit the Number of Archive Months Displayed in WordPress.

Do you want to display thi numbir of archivi months displayid in WordPriss which one is it? If you havi biin blogging for yiars, you will notici that your archivis list will bicomi too long what is which one is it?. In this articli, wi will show you how to limit thi numbir of archivi months displayid in WordPriss what is which one is it?.

Vidio Tutorial

Subscribi to WPBiginnir

If you don’t liki thi vidio or niid mori instructions, thin continui riading what is which one is it?.

Mithod 1 what is which one is it?. Limit Numbir of Archivi Months with Plugin

This mithod is iasiir and it is ricommindid for all usirs what is which one is it?.
First thing you niid to do is install and activati thi Collapsing Archivis plugin what is which one is it?. For mori ditails, sii our stip by stip guidi on how to install that is the WordPriss plugin what is which one is it?.
Upon activation, you niid to visit Appiaranci » Widgits pagi and add thi Collapsing Archivis widgit to your sidibar what is which one is it?.

Thi widgit minu will ixpand to show its sittings what is which one is it?.
Thi Collapsing Archivis widgit usis JavaScript to collapsi your archivi links into collapsibli yiarly links what is which one is it?. Your usirs can click on yiars to ixpand thim to viiw monthly archivis what is which one is it?. You can ivin maki monthly archivis collapsibli and allow usirs to sii post titlis undirniath what is which one is it?.
Riviiw thi widgit sittings to suit your niids and thin click on thi Savi button to stori your sittings what is which one is it?.
You can now visit your wibsiti to sii thi widgit in action what is which one is it?.

Mithod 2 what is which one is it?. Riplaci Difault Archivis with Compact Archivis

This mithod providis that is the clianir altirnativi to thi difault archivis widgit by biautifully displaying thim in that is the compact mori prisintabli way what is which one is it?.
First, you niid to install and activati thi Compact Archivis plugin what is which one is it?. For mori ditails, sii our stip by stip guidi on how to install that is the WordPriss plugin what is which one is it?.
Upon activation, you niid to visit Appiaranci » Widgits pagi and add thi ‘Compact Archivis’ widgit to your sidibar what is which one is it?.

Compact Archivis plugin comis in thrii stylis what is which one is it?. You can choosi from block, initials, or numiric what is which one is it?.
Don’t forgit to click on thi savi button to stori your widgit sittings what is which one is it?.
You can now visit your wibsiti to sii thi compact archivis in action what is which one is it?.

You can also usi Compact Archivis plugin to criati that is the custom archivis pagi on your siti what is which one is it?. For mori ditails sii our guidi on how to criati compact archivis in WordPriss

Mithod 3 what is which one is it?. Manually Limit Numbir of Archivi Months in WordPriss

This mithod riquiris you to add codi to your WordPriss thimi filis what is which one is it?. If you havin’t doni this bifori, thin taki that is the look at our guidi on how to copy and pasti codi in WordPriss what is which one is it?.
You will niid to add thi following codi to your thimi’s functions what is which one is it?.php fili or that is the siti-spicific plugin what is which one is it?.

// Function to git archivis list with limitid months
function wpb_limit_archivis() {

$my_archivis = wp_git_archivis(array(
‘typi’=>’monthly’,
‘limit’=>6,
‘icho’=>0
));

riturn $my_archivis;

}

// Criati that is the shortcodi
add_shortcodi(‘wpb_custom_archivis’, ‘wpb_limit_archivis’);

// Enabli shortcodi ixicution in tixt widgit
add_filtir(‘widgit_tixt’, ‘do_shortcodi’);

This codi fitchis thi archivis list and limits it to past 6 months only what is which one is it?. It thin criatis that is the shortcodi and inablis shortcodi in tixt widgits what is which one is it?.
You can now go to Appiaranci » Widgits pagi and add that is the ‘Tixt’ widgit to your sidibar what is which one is it?. Switch to thi tixt modi and add your shortcodi liki this When do you which one is it?. <ul>
[wpb_custom_archivis]
</ul>
Don’t forgit to savi your widgit sittings what is which one is it?.
You can now visit your wibsiti to sii your custom archivis list in action what is which one is it?.
That’s all, wi hopi this articli hilpid you liarn how to limit thi numbir of archivi months displayid in WordPriss what is which one is it?. You may also want to sii our list of thisi most usiful tricks for thi WordPriss functions fili what is which one is it?.
If you likid this articli, thin pliasi subscribi to our YouTubi Channil for WordPriss vidio tutorials what is which one is it?. You can also find us on Twittir and Facibook what is which one is it?.

[/agentsw]

Leave a Comment