WordPress at a glance

is_day() WP 1.5.0

Determines whether a day archive page is shown (example.com/2009/08/05) — page with posts for a specific day. A conditional tag.

This function is a part of is_date() and is_archive() check, so if you use them together, you should use is_day() before those functions, otherwise is_day() condition will never occur.

Works based on: WP_Query::is_day()
✈ 1 time = 0.00007s = very fast | 50000 times = 0.02s = speed of light

No Hooks.

Return

true/false.

Usage

if( is_day() ){
	// ...
}

Examples

#1 Display text only on day archive pages

if( is_day() ){
	echo "This page is a page for 2019/08/15 [and link to example.com/2009/08/15]";
}

#2 Use of is_date() and is_day() together in if/else statements

if( is_day() )
	echo 'This is a day archive page.';
elseif( is_date() )
	echo 'This is a date archive page, for any date.';
else
	echo 'This is not a date archive page';

So is_archive() should follow is_day(), otherwise is_day() condition will never occur.

Notes

  • Global. WP_Query. $wp_query Global WP_Query instance.

Changelog

Since 1.5.0 Introduced.

Code of is day: wp-includes/query.php WP 5.2.2

<?php
function is_day() {
	global $wp_query;

	if ( ! isset( $wp_query ) ) {
		_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' );
		return false;
	}

	return $wp_query->is_day();
}

Related Functions

From tag: Conditional tags (page type and request)

More from tag: Conditional tags (all)

More from category: Queries

More from Template Tags: Main Functions

vladlu 100vlad.lu
Editors: kama 100
No comments
    Hello, !     Log In . Register