get_month_link

Retrieves the permalink for the month archives with year.

Description

(string) get_month_link( (bool|int) $year, (bool|int) $month ); 

Returns (string)

The permalink for the specified month and year archive.

Parameters (2)

0. $year (bool|int)
False for current year. Integer of year.
1. $month (bool|int)
False for current month. Integer of month.

Usage

  1. if ( !function_exists( 'get_month_link' ) ) { 
  2. require_once ABSPATH . WPINC . '/link-template.php'; 
  3.  
  4. // False for current year. Integer of year. 
  5. $year = null; 
  6.  
  7. // False for current month. Integer of month. 
  8. $month = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = get_month_link($year, $month); 
  12.  

Defined (1)

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

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