the_date() – Displays or retrieves the date the current post was written (once per date)

You appear to be a bot. Output may be restricted

Description

Displays or retrieves the date the current post was written (once per date)

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'.

Usage

$string|void = the_date( $format, $before, $after, $display );

Parameters

$format
( string ) optional – Optional. PHP date format. Defaults to the 'date_format' option.
$before
( string ) optional – Optional. Output before the date. Default empty.
$after
( string ) optional – Optional. Output after the date. Default empty.
$display
( bool ) optional default: 1 – Optional. Whether to echo the date or return it. Default true.

Returns

string|void String if retrieving.

Source

File name: wordpress/wp-includes/general-template.php


Lines:

1 to 31 of 31
function the_date( $format = '', $before = '', $after = '', $display = true ) {
  global $currentday, $previousday;

  $the_date = '';

  if ( is_new_day() ) {
    $the_date    = $before . get_the_date( $format ) . $after;
    $previousday = $currentday;
  }

  
/**
 * Filters the date a post was published for display.
 *
 * @since 0.71
 *
 * @param string $the_date The formatted date string.
 * @param string $format   PHP date format.
 * @param string $before   HTML output before the date.
 * @param string $after    HTML output after the date.
 */
  $the_date = apply_filters( 'the_date', $the_date, $format, $before, $after );

  if ( $display ) {
    echo $the_date;
  } else {
    return $the_date;
  }
}
 

 View on GitHub View on Trac