Displays or retrieves the date of the post (once per date).
Description
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'.
Parameters
$formatstringoptional
PHP date format. Defaults to the 'date_format' option.Default: ''
$beforestringoptional
Output before the date. Default empty.Default: ''
$afterstringoptional
Output after the date. Default empty.Default: ''
$displaybooloptional
Whether to echo the date or return it. Default true.Default: true
Return
string|void
String if retrieving.
Hooks fired · 1
One hook fires while the_date() runs, in this order:
2675functionthe_date($format='',$before='',$after='',$display=true){2676global$currentday,$previousday;26772678$the_date='';26792680if(is_new_day()){2681$the_date=$before.get_the_date($format).$after;2682$previousday=$currentday;2683}26842685/**2686 * Filters the date of the post, for display.2687 *2688 * @since 0.712689 *2690 * @param string $the_date The formatted date string.2691 * @param string $format PHP date format.2692 * @param string $before HTML output before the date.2693 * @param string $after HTML output after the date.2694 */2695$the_date=apply_filters('the_date',$the_date,$format,$before,$after);26962697if($display){2698echo$the_date;2699}else{2700return$the_date;2701}2702}
History
Introduced in 0.71. One change between 6.7.7 and 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
7.0.4
Return type changed from string|void to string|null.verified against source
0.71
Introduced.from the docblock
About this page
Parsed data
Generated from the wordpress-develop 6.9.7 tag, from src/wp-includes/general-template.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.