WordPress wp_get_archives() Function

Beginner
4 min read
Updated: Nov 2026
3 examples
Template tag

Definition

In WordPress, wp_get_archives() prints a list of archive links, such as one link for each month that has posts. It is the function behind the Archives widget.

You choose the list with the type argument: monthly (default), yearly, daily, weekly, postbypost, or alpha. Each row is built with get_archives_link().

Syntax

Call it inside a list, or pass an array of arguments.

WordPress
<ul>
<?php
wp_get_archives( array(
  'type'  => 'monthly',
  'limit' => 6,
) );
?>
</ul>
CallWhat it does
wp_get_archives()Prints monthly archive links.
wp_get_archives( 'type=yearly' )Prints yearly archive links.
wp_get_archives( array( 'format' => 'option' ) )Prints option tags for a dropdown.

The default html format prints <li> items, so wrap it in a <ul>.

Full declaration
WordPress
wp_get_archives( string|array $args = '' ): void|string

Parameters

ParameterDescription
$argsstring|array. Options: type, limit, format (html, option, link, custom), before, after, show_post_count, echo, order, post_type. Default is an empty string.

Return Value

Return ValueDescription
voidWhen echo is 1 (default), the list is printed.
stringWhen echo is 0, the list is returned as a string.

WordPress Examples

Three short theme examples. Each one shows the code and what it prints.

Example 1 — Monthly archives

List the last three months.

WordPress
<ul>
  <?php wp_get_archives( array( 'type' => 'monthly', 'limit' => 3 ) ); ?>
</ul>

How It Works

  1. type is monthly, which is also the default.
  2. limit keeps only the latest 3 months.
  3. Each row is a list item with a link.

Example 2 — Yearly archives with post counts

Show how many posts each year has.

WordPress
<ul>
  <?php wp_get_archives( array(
    'type'            => 'yearly',
    'show_post_count' => true,
  ) ); ?>
</ul>

How It Works

  1. yearly gives one link per year.
  2. show_post_count adds the number in brackets.
  3. The counts come from published posts.

Example 3 — A dropdown of months

Use the option format in a select box.

WordPress
<select onchange="document.location.href=this.value;">
  <option value="">Select month</option>
  <?php wp_get_archives( array(
    'type'   => 'monthly',
    'format' => 'option',
    'limit'  => 3,
  ) ); ?>
</select>

How It Works

  1. format is option, so each row is an option tag.
  2. The inline script opens the chosen month.
  3. The first option is a placeholder.

Frequently Asked Questions

It prints a list of archive links, such as one for each month or year that has posts.
monthly (default), yearly, daily, weekly, postbypost, and alpha.
Set echo to 0, for example wp_get_archives( array( 'echo' => 0 ) ).
Use format => option inside a select tag and add a small script to open the chosen link.

Next: wp_login_form()

Print or return a ready-made login form for the front end.

wp_login_form() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful