Ready to get started?Download WordPress


Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/get year link



Returns the yearly archive URL to a specific year for use in PHP. It does NOT display the URL. If year is set to '', the tag returns the URL for the current year's archive.


 <?php get_year_link$year ); ?> 


(integer) (optional) The year for the archive. Use '' to assign current year.
Default: None


Year as Link

Returns the URL for the current year's archive, displaying it as a link in the anchor tag by using the PHP echo command.

<a href="<?php echo get_year_link(''); ?>">Posts from this year</a>

Year as a variable

Returns URL for the archive year 2003, assigning it to the variable $year03. The variable can then be used elsewhere in a page.

<?php $year03 = get_year_link(2003); ?>

Using With PHP Variables

PHP code block for use within The Loop: Assigns year to the variable $arc_year. This is used with the get_year_link() tag, which returns the URL as a link to the yearly archive for a post, displaying it within an anchor tag with the PHP echo command. See Formatting Date and Time for info on format strings used in get_the_time() tag.

<?php $archive_year = get_the_time('Y'); ?>

<a href="<?php echo get_year_link( $archive_year ); ?>"><?php the_time('Y'); ?> archive</a>


Since: 1.5.0

Source File

get_year_link() is located in wp-includes/link-template.php.


get_calendar(), get_day_link(), get_month_link(), get_the_date(), get_the_time(), get_year_link(), single_month_title(), the_date(), the_date_xml(), the_modified_date(), get_the_modified_date(), the_modified_time(), get_the_modified_time(), the_time()

See also index of Function Reference and index of Template Tags.