php - Send 404 status code on a specific WordPress page? -
i need send 404 status code on specific page in wordpress. page not using 404.php template. preferably, within theme files, , not using .htaccess.
here have that's not working.
function my_404() { if ( is_page( 813 ) ) { header('http/1.1 404 not found'); echo 'testing123'; //this outputs fine, know code running on correct page } } add_action( 'wp', 'my_404' );
if successful, page exact same, except running through website analyzer tell me it's returning 404 code. however, using code, still returns 200 no matter what.
try this, should expected result:
function my_404() { if ( is_page( 813 ) ) { global $wp_query; $wp_query->set_404(); status_header(404); nocache_headers() } } add_action( 'wp', 'my_404' );
Comments
Post a Comment