WordPress wp_get_archives Example: Build Archive Navigation Cleanly
Use wp_get_archives() to generate archive navigation without hand-building date links or rewriting classic WordPress archive output.
Published
May 1, 2026
Reading Time
2 min read
Updated
May 1, 2026

Implementation Notes
Extension points, code paths, and implementation choices that should survive contact with production.
Best For
WordPress developers, agencies, and technical teams building custom plugin or theme functionality with cleaner operational defaults.
Primary Topics
Editorial Focus
Build Pattern: Extension points, code paths, and implementation choices that should survive contact with production. Updated on May 1, 2026.
Full Report
Last reviewed: May 1, 2026
Archive navigation is still useful on content-heavy blogs, but it is often implemented as a hardcoded month list that becomes difficult to style or extend. wp_get_archives() is the core helper for generating archive links with predictable formats and output modes.
This guide shows how to use wp_get_archives() cleanly for archive navigation without hand-building date links in templates.
Render a monthly archive list
<?php
wp_get_archives(
array(
'type' => 'monthly',
'limit' => 12,
'show_post_count' => true,
)
);
This is the simplest way to surface archive history in a sidebar, footer, or dedicated archive page.
Return the output as a string when the layout needs full control
$archives = wp_get_archives(
array(
'type' => 'yearly',
'echo' => false,
)
);
if ( $archives ) {
echo '<nav class=\"archive-nav\">' . $archives . '</nav>';
}
Using echo => false is the clean way to wrap the generated archive links without rewriting the underlying helper.
Know what problem it actually solves
wp_get_archives() is for archive link output, not for generalized post queries or custom content dashboards. If the UI needs filtered cards or custom post types, the solution probably belongs elsewhere.
Keep expectations realistic around custom content models
This helper is built around classic post archives. For more specialized archive flows, custom templates or queries are often more appropriate than forcing everything through one archive helper.
Production checklist
- Choose the archive type that matches the real navigation pattern.
- Use
echo => falsewhen wrappers or custom placement are required. - Limit long lists so archive navigation stays scannable.
- Use post counts only when they add real value to readers.
- Test archive output on mobile sidebars and narrow layouts.
- Do not treat this helper as a substitute for custom archive templates.
Common mistakes
- Hand-building archive month links. Core already handles the common cases.
- Dumping an unbounded archive list into dense layouts. Long navigation blocks become visual noise.
- Using archive helpers for custom query UIs. Different problems need different tools.
- Forgetting output control.
echo => falseoften produces cleaner templates. - Assuming archive navigation is always useful. Some content models need topical rather than date-based discovery.
Related reading
If the archive page itself needs pagination cleanup, pair this with the paginate_links guide. If the template rendering differs across archive types, continue with the template hierarchy article.


