get_year_link

Retrieves the permalink for the year archives.

Description

(string) get_year_link( (int|bool) $year ); 

Returns (string)

The permalink for the specified year archive.

Parameters (1)

0. $year (int|bool)
False for current year or year for permalink.

Usage

  1. if ( !function_exists( 'get_year_link' ) ) { 
  2. require_once ABSPATH . WPINC . '/link-template.php'; 
  3.  
  4. // False for current year or year for permalink. 
  5. $year = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = get_year_link($year); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/link-template.php  
  1. function get_year_link( $year ) { 
  2. global $wp_rewrite; 
  3. if ( !$year ) 
  4. $year = gmdate('Y', current_time('timestamp')); 
  5. $yearlink = $wp_rewrite->get_year_permastruct(); 
  6. if ( !empty($yearlink) ) { 
  7. $yearlink = str_replace('%year%', $year, $yearlink); 
  8. $yearlink = home_url( user_trailingslashit( $yearlink, 'year' ) ); 
  9. } else { 
  10. $yearlink = home_url( '?m=' . $year ); 
  11.  
  12. /** 
  13. * Filters the year archive permalink. 
  14. * @since 1.5.0 
  15. * @param string $yearlink Permalink for the year archive. 
  16. * @param int $year Year for the archive. 
  17. */ 
  18. return apply_filters( 'year_link', $yearlink, $year );