WordPress at a glance

get_year_link() WP 1.0

Retrieves the permalink for the year archives.

  • Global. WP_Rewrite. $wp_rewrite
✈ 1 time = 0.000159s = fast | 50000 times = 3.51s = fast PHP 7.0.8, WP 4.6
Hooks from 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.

Code of get_year_link: wp-includes/link-template.php VER 4.9.8

<?php
function get_year_link( $year ) {
	global $wp_rewrite;
	if ( !$year )
		$year = gmdate('Y', current_time('timestamp'));
	$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