404 status helper function for WordPress themes.
You can install the package via Composer:
composer require mindkomm/theme-lib-404
Name | Summary | Type | Returns/Description |
---|---|---|---|
force_404 | Forces 404 headers on a query. |
Forces 404 headers on a query.
Use this function in a WordPress template file.
When a template other than 404.php is loaded, the proper headers for a 404 status are not set properly. This function can be used to set proper headers even after a template file is loaded.
What you have to do after this request is to include the 404 template and exit after it.
PHP
if ( 'publish' !== $post->post_status ) {
force_404();
Timber::render( '404.twig', $context );
exit;
}
This is a library that we use at MIND to develop WordPress themes. You’re free to use it, but currently, we don’t provide any support.