W3 Mind Logo
Home » How to Limit the Number of Archive Months Displayed in WordPress

How to Limit the Number of Archive Months Displayed in WordPress

If you want to display the number of archive months in WordPress then you just need to add the below function in functions.php file of your current active theme.

After adding the below function in functions.php use the shortcode in WordPress text editor or text widget. This will display archives list with limited months which you will set in the below function.


// Function to get archives list with limited months
function wpb_limit_archives() { 
 
$my_archives = wp_get_archives(array(
    'type'=>'monthly', 
    'limit'=>12,
    'echo'=>0
));
     
return $my_archives; 
 
} 
 
// Create a shortcode
add_shortcode('w3m_custom_archives', 'w3m_limit_archives'); 
 
// Enable shortcode execution in text widget
add_filter('widget_text', 'do_shortcode');

About Author
W3Mind

W3Mind

W3Mind focuses on Blogging, Make Money Online, SEO, Business Blogging, Social Media, WordPress, Internet Tools, Web Design and Development.
Give it a Share
Facebook
Twitter
LinkedIn
You May Also Like
Leave a Reply

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

How to
START A
BLOG
(step by step)
Load WordPress Sites in as fast as 37ms!