is_404()
Checks whether the 404 error page is displayed (HTTP 404: page not found). Conditional tag.
No Hooks.
Returns
true|false. Whether the query is a 404 error.
Usage
is_404();
Examples
#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
}
Notes
- Global. WP_Query.
$wp_queryWordPress Query object.
Changelog
| Since 1.5.0 | Introduced. |
is_404() is 404 code WP 7.0
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();
}