get_year_link( int|false $year ): string

Retrieves the permalink for the year archives.


Integer of year. False for current year.


string The permalink for the specified year archive.


function get_year_link( $year ) {
	global $wp_rewrite;
	if ( ! $year ) {
		$year = current_time( 'Y' );
	$yearlink = $wp_rewrite->get_year_permastruct();
	if ( ! empty( $yearlink ) ) {
		$yearlink = str_replace( '%year%', $year, $yearlink );
		$yearlink = home_url( user_trailingslashit( $yearlink, 'year' ) );
	} else {
		$yearlink = home_url( '?m=' . $year );

	 * Filters the year archive permalink.
	 * @since 1.5.0
	 * @param string $yearlink Permalink for the year archive.
	 * @param int    $year     Year for the archive.
	return apply_filters( 'year_link', $yearlink, $year );


apply_filters( ‘year_link’, string $yearlink, int $year )

Filters the year archive permalink.



User Contributed Notes

  1. Skip to note 6 content

    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>

You must log in before being able to contribute a note or feedback.