The is_time() WordPress PHP function determines whether the query is for a specific time.
Usage
if (is_time()) {
// Do something if the query is for a specific time.
}
Parameters
- None
More information
See WordPress Developer Resources: is_time()
Examples
Check if it’s a time-based query in a theme
Check if the current query is for a specific time and display a message if it is.
if (is_time()) {
echo 'You are viewing a time-based archive!';
}
Display different content for time-based queries
Display different content for time-based queries and other queries in the loop.
if (is_time()) {
echo 'You are viewing a time-based archive!';
} else {
echo 'You are not viewing a time-based archive!';
}
Add a CSS class for time-based queries
Add a CSS class to the body element if the query is for a specific time.
function add_time_based_class($classes) {
if (is_time()) {
$classes[] = 'time-based-archive';
}
return $classes;
}
add_filter('body_class', 'add_time_based_class');
Display a custom title for time-based archives
Create a custom title for time-based archives in the header.
function custom_title() {
if (is_time()) {
return 'Time-based Archive';
}
return get_the_title();
}
echo custom_title();
Hide the sidebar for time-based archives
Hide the sidebar on time-based archives using a conditional statement.
if (!is_time()) {
get_sidebar();
}