WordPress at a glance

get_year_link() WP 1.0

Retrieves the permalink for the year archives.

✈ 1 time = 0.000159s = fast | 50000 times = 3.51s = fast | PHP 7.0.8, WP 4.6
Hooks from the function
Return

String. The permalink for the specified year archive.

Usage

get_year_link( $year );
$year(int/true/false) (required)
False for current year or year for permalink.

Notes

  • Global. WP_Rewrite. $wp_rewrite

Changelog

Since 1.5.0 Introduced.

Code of get year link: wp-includes/link-template.php WP 5.2.2

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

Related Functions

From tag: Link (URL)

More from category: Archives

No comments
    Hello, !     Log In . Register