WordPress get_archives_link() Function

Beginner
4 min read
Updated: Nov 2026
3 examples
Link builder

Definition

In WordPress, get_archives_link() builds one archive link and returns it as a string. It is the tool that wp_get_archives() uses for every row.

You choose the wrapper with $format: a list item (html), a dropdown choice (option), a head link (link), or your own markup (custom).

Syntax

Pass the address and the link text. Echo the returned string.

WordPress
<?php
echo get_archives_link(
  get_month_link( 2026, 11 ),
  'November 2026'
);
CallWhat it does
get_archives_link( $url, $text )A list item with a link (html format).
get_archives_link( $url, $text, 'option' )An option tag for a select box.
get_archives_link( $url, $text, 'custom', '<p>', '</p>' )A link wrapped in your own tags.

It returns the link. It does not echo.

Full declaration
WordPress
get_archives_link( string $url, string $text, string $format = 'html', string $before = '', string $after = '', bool $selected = false ): string

Parameters

ParameterDescription
$urlstring. The address the link points to.
$textstring. The link text.
$formatstring. html (default), option, link, or custom.
$beforestring. Text or HTML before the link. Default is empty.
$afterstring. Text or HTML after the link. Default is empty.
$selectedbool. Mark the option as selected (for the option format). Default is false.

Return Value

Return ValueDescription
stringThe archive link markup for the chosen format.

WordPress Examples

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

Example 1 — A list item link

The default format is a list item.

WordPress
<ul>
<?php echo get_archives_link(
  get_month_link( 2026, 11 ),
  'November 2026'
); ?>
</ul>

How It Works

  1. get_month_link() builds the month archive URL.
  2. The default format wraps the link in <li>.
  3. echo prints the returned string.

Example 2 — A dropdown option

Use the option format inside a select box.

WordPress
<select>
<?php echo get_archives_link(
  get_month_link( 2026, 11 ),
  'November 2026',
  'option', '', '', true
); ?>
</select>

How It Works

  1. The format option prints an <option> tag.
  2. The last value true marks it as selected.
  3. The URL becomes the option value.

Example 3 — Custom wrapper

Wrap the link in your own tags.

WordPress
<?php echo get_archives_link(
  get_year_link( 2026 ),
  '2026 posts',
  'custom',
  '<p class="archive-row">',
  '</p>'
); ?>

How It Works

  1. With custom, only your before and after text is added.
  2. No li or option tag is used.
  3. You control the markup completely.

Frequently Asked Questions

It returns one archive link as a string, in the format you pick.
No. Use echo to print it.
html (list item), option (dropdown choice), link (a link tag for the head), and custom (your own wrapper).
Use wp_get_archives(). It finds the archives and calls get_archives_link() for each one.

Next: get_bloginfo()

Return site information such as the name, tagline, URL, and version as a string.

get_bloginfo() 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.

10 people found this page helpful