get_year_link() WordPress Function

The get_year_link() function retrieves the link for a given year. This function is useful for creating permalinks to yearly archives. It accepts a year as a parameter and returns a link to the corresponding archive. If no year is specified, the current year is used.

get_year_link( int|false $year ) #

Retrieves the permalink for the year archives.


Parameters

$year

(int|false)(Required)Integer of year. False for current year.


Top ↑

Return

(string) The permalink for the specified year archive.


Top ↑

Source

File: wp-includes/link-template.php

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 );
}


Top ↑

Changelog

Changelog
VersionDescription
1.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More