WordPress at a glance

is_404() WP 1.5.0

Checks whether the 404 error page is displayed (HTTP 404: page not found). Conditional tag.

No Hooks.


true|false. Whether the query is a 404 error.




#1 Determine if the current page is 404

If a theme template doesn't have 404.php file then you can add following code to single.php.

if ( is_404() ) {        
	// you can add search form here          
	// so the user can find a needed post        


  • Global. WP_Query. $wp_query WordPress Query object.


Since 1.5.0 Introduced.

Code of is_404() WP 5.7.1

function is_404() {
	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_404();

From tag: Conditional tags (page type and request)

More from tag: Conditional tags (all)

More from category: Queries

More from Template Tags: Main Functions

No comments
    Log In