Created
December 7, 2015 11:45
-
-
Save anonymous/864c81463d417e4c3b79 to your computer and use it in GitHub Desktop.
Safely force WordPress to 404
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// safe 404 | |
// Force WordPress to 404 on the current template | |
// SEO Friendly! | |
// ================================================= | |
function safe_404(){ | |
global $wp_query; | |
$wp_query->set_404(); | |
status_header(404); | |
nocache_headers(); | |
get_template_part('404'); | |
exit; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Located in functions.php | |
* | |
* This function will: | |
* - Interrupt the current WP_Query global. | |
* - Force WordPress to include the 404 template automatically. | |
* - Declare a 404 Not Found HTTP code. | |
* | |
*/ | |
safe_404(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment