Family Encyclopedia >> Electronics

How to Limit Monthly Archives in WordPress: Display Only Recent Months

Running a long-term WordPress blog? Your archive widget can quickly become overwhelming with years of monthly links. As experienced WordPress users ourselves, we've streamlined countless sites. Here's how to limit the number of archive months shown, keeping your sidebar clean and user-friendly.

How to Limit Monthly Archives in WordPress: Display Only Recent Months

Video Walkthrough

Subscribe to WPBeginner for more tips. Prefer reading? Scroll on for detailed steps.

Method 1: Use the Collapsible Archives Plugin (Recommended for Beginners)

This user-friendly approach collapses archives into expandable sections—perfect for any skill level.

Install and activate the Collapsible Archives plugin. See our step-by-step plugin installation guide for details.

Head to Appearance » Widgets and drag the Collapsible Archives widget to your sidebar.

How to Limit Monthly Archives in WordPress: Display Only Recent Months

The widget expands with customizable options. It uses JavaScript to group links by year (expandable to months, even post titles). Tweak settings to fit your site, then hit Save.

Preview your site—archives now collapse neatly.

How to Limit Monthly Archives in WordPress: Display Only Recent Months

Method 2: Switch to Compact Archives for a Sleek Look

For a modern, space-saving display without long lists.

Install and activate the Compact Archives plugin (plugin guide here).

Add the Compact Archives widget via Appearance » Widgets.

How to Limit Monthly Archives in WordPress: Display Only Recent Months

Choose from block, initials, or numeric styles. Save, then check your live site.

How to Limit Monthly Archives in WordPress: Display Only Recent Months

Bonus: Use it for a custom archives page. Details in our Compact Archives guide.

Method 3: Custom Code to Limit Archives Manually

For developers: Precisely control via code. Backup first and follow our code editing guide.

Add this to your theme's functions.php or a site-specific plugin:

function wpb_limit_archives() {
    $my_archives = wp_get_archives( array(
        'type'  => 'monthly',
        'limit' => 6,
        'echo'  => 0
    ) );
    return $my_archives;
}
add_shortcode( 'wpb_custom_archives', 'wpb_limit_archives' );
add_filter( 'widget_text', 'do_shortcode' );

This fetches the last 6 months, creates a shortcode, and enables it in text widgets.

In Appearance » Widgets, add a Text widget to your sidebar. Switch to Text mode and insert:

<ul>
[wpb_custom_archives]
</ul>

Save and view your site—custom archives live.

Pro tip: Adjust 'limit' => 6 as needed.

That's it! Your archives are now concise. Explore more in our top functions.php hacks.

Liked this? Subscribe to our YouTube channel, follow on Twitter, or like on Facebook for WordPress expertise.