get_year_link( int|bool $year )
Retrieves the permalink for the year archives.
Description Description
Parameters Parameters
- $year
-
(int|bool) (Required) False for current year or year for permalink.
Return Return
(string) The permalink for the specified year archive.
Source 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 code Collapse full source code View on Trac
Changelog Changelog
Version | Description |
---|---|
1.5.0 | Introduced. |
User Contributed Notes User Contributed Notes
You must log in before being able to contribute a note or feedback.
Year as Link
Returns the URL for the current year’s archive, displaying it as a link in the anchor tag by using the PHP echo command.
Year as a variable
Returns URL for the archive year 2003, assigning it to the variable $year03. The variable can then be used elsewhere in a page.
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.