WordPress get_archives_link() Function

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.
<?php
echo get_archives_link(
get_month_link( 2026, 11 ),
'November 2026'
);
| Call | What 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
get_archives_link( string $url, string $text, string $format = 'html', string $before = '', string $after = '', bool $selected = false ): string
Parameters
| Parameter | Description |
|---|
$url | string. The address the link points to. |
$text | string. The link text. |
$format | string. html (default), option, link, or custom. |
$before | string. Text or HTML before the link. Default is empty. |
$after | string. Text or HTML after the link. Default is empty. |
$selected | bool. Mark the option as selected (for the option format). Default is false. |
Return Value
| Return Value | Description |
|---|
| string | The 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.
<ul>
<?php echo get_archives_link(
get_month_link( 2026, 11 ),
'November 2026'
); ?>
</ul>
<ul>
<li><a href='https://example.com/2026/11/'>November 2026</a></li>
</ul>
How It Works
get_month_link() builds the month archive URL.- The default format wraps the link in
<li>. echo prints the returned string.
Example 2 — A dropdown option
Use the option format inside a select box.
<select>
<?php echo get_archives_link(
get_month_link( 2026, 11 ),
'November 2026',
'option', '', '', true
); ?>
</select>
<select>
<option value='https://example.com/2026/11/' selected='selected'> November 2026 </option>
</select>
How It Works
- The format
option prints an <option> tag. - The last value
true marks it as selected. - The URL becomes the option value.
Example 3 — Custom wrapper
Wrap the link in your own tags.
<?php echo get_archives_link(
get_year_link( 2026 ),
'2026 posts',
'custom',
'<p class="archive-row">',
'</p>'
); ?>
<p class="archive-row"><a href='https://example.com/2026/'>2026 posts</a></p>
How It Works
- With
custom, only your before and after text is added. - No
li or option tag is used. - 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
Developer, cloud engineer, and technical writer
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