The is_date() WordPress PHP function determines whether the query is for an existing date archive.
Usage
if (is_date()) { // Perform some action. }
Parameters
- No parameters.
More information
See WordPress Developer Resources: is_date()
Examples
Display a message on date archive pages
if (is_date()) { echo 'Welcome to the date archive!'; }
Apply a specific CSS class on date archive pages
$body_class = 'default'; if (is_date()) { $body_class = 'date-archive'; } echo '<body class="' . $body_class . '">';
Show a date-specific widget on date archive pages
if (is_date()) { dynamic_sidebar('date-archive-widget'); } else { dynamic_sidebar('default-sidebar'); }
Use a custom date archive template
if (is_date()) { get_template_part('archive', 'date'); } else { get_template_part('archive'); }
Display a custom title for date archive pages
if (is_date()) { $title = 'Date Archive: ' . get_the_date(); } else { $title = get_the_title(); } echo '<h1>' . $title . '</h1>';