get_day_link

Retrieves the permalink for the day archives with year and month.

Description

(string) get_day_link( (bool|int) $year, (bool|int) $month, (bool|int) $day ); 

Returns (string)

The permalink for the specified day, month, and year archive.

Parameters (3)

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

Usage

  1. if ( !function_exists( 'get_day_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. // False for current day. Integer of day. 
  11. $day = null; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = get_day_link($year, $month, $day); 
  15.  

Defined (1)

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

/wp-includes/link-template.php  
  1. function get_day_link($year, $month, $day) { 
  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. if ( !$day ) 
  8. $day = gmdate('j', current_time('timestamp')); 
  9.  
  10. $daylink = $wp_rewrite->get_day_permastruct(); 
  11. if ( !empty($daylink) ) { 
  12. $daylink = str_replace('%year%', $year, $daylink); 
  13. $daylink = str_replace('%monthnum%', zeroise(intval($month), 2), $daylink); 
  14. $daylink = str_replace('%day%', zeroise(intval($day), 2), $daylink); 
  15. $daylink = home_url( user_trailingslashit( $daylink, 'day' ) ); 
  16. } else { 
  17. $daylink = home_url( '?m=' . $year . zeroise( $month, 2 ) . zeroise( $day, 2 ) ); 
  18.  
  19. /** 
  20. * Filters the day archive permalink. 
  21. * @since 1.5.0 
  22. * @param string $daylink Permalink for the day archive. 
  23. * @param int $year Year for the archive. 
  24. * @param int $month Month for the archive. 
  25. * @param int $day The day for the archive. 
  26. */ 
  27. return apply_filters( 'day_link', $daylink, $year, $month, $day );