the_date

Display or Retrieve the date the current post was written (once per date).

Description

(string|void) the_date( (string) $d = '', (string) $before = '', (string) $after = '', (bool) $echo = true ); 

Will only output the date if the current post's date is different from the previous one output.

i.e. Only one date listing will show per day worth of posts shown in the loop, even if the function is called several times for each post.

HTML output can be filtered with the_date.. Date string output can be filtered with get_the_date.

Returns (string|void)

String if retrieving.

Parameters (4)

0. $d — Optional. (string) => ''
PHP date format defaults to the date_format option if not specified.
1. $before — Optional. (string) => ''
Output before the date.
2. $after — Optional. (string) => ''
Output after the date.
3. $echo — Optional. (bool) => true
Optional, default is display. Whether to echo the date or return it.

Usage

  1. if ( !function_exists( 'the_date' ) ) { 
  2. require_once ABSPATH . WPINC . '/general-template.php'; 
  3.  
  4. // Optional. PHP date format defaults to the date_format option if not specified. 
  5. $d = ''; 
  6.  
  7. // Optional. Output before the date. 
  8. $before = ''; 
  9.  
  10. // Optional. Output after the date. 
  11. $after = ''; 
  12.  
  13. // Optional, default is display. Whether to echo the date or return it. 
  14. $echo = true; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = the_date($d, $before, $after, $echo); 
  18.  

Defined (1)

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

/wp-includes/general-template.php  
  1. function the_date( $d = '', $before = '', $after = '', $echo = true ) { 
  2. global $currentday, $previousday; 
  3.  
  4. if ( is_new_day() ) { 
  5. $the_date = $before . get_the_date( $d ) . $after; 
  6. $previousday = $currentday; 
  7.  
  8. /** 
  9. * Filters the date a post was published for display. 
  10. * @since 0.71 
  11. * @param string $the_date The formatted date string. 
  12. * @param string $d PHP date format. Defaults to 'date_format' option 
  13. * if not specified. 
  14. * @param string $before HTML output before the date. 
  15. * @param string $after HTML output after the date. 
  16. */ 
  17. $the_date = apply_filters( 'the_date', $the_date, $d, $before, $after ); 
  18.  
  19. if ( $echo ) 
  20. echo $the_date; 
  21. else 
  22. return $the_date;