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.
Return
(string) The permalink for the specified year archive.
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 );
}
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
| Version | Description |
|---|---|
| 1.5.0 | Introduced. |