WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

i want to do something if my url is /pagethatdontexist But I dont want wp sending 404 headers. I tried this:

add_action('wp', array($this,'awp'));   
function awp(){
global $wp_query ;
if($wp_query->query_vars['name'] == 'pagethatdontexist')
    debug('yes were at pagethatdontexist');;
$wp_query->is_404 = false;

Which works, but still, 404 headers are sent.

Where can I hook in and tell wp not to send the 404?

EDIT -- well, this seems to do the trick, I'm not sure if it's Kosher.

function filter_status_header(  $status_header, $header, $text, $protocol ){
    global $wp_query;
    if (iDontWant404()){
        $wp_query->is_404 = false;// still sends 404 unless:
        return 'HTTP/1.1 200 OK';  
        return $status_header;
share|improve this question
What do you want to do instead of going to the 404 page? – Charles Clarkson Sep 4 '13 at 20:16
Wul, whatever I want. I'll figure sth out from there. First I've got to get it to not 404 if we are on a url that I want. – Doug Cassidy Sep 4 '13 at 20:43
up vote 2 down vote accepted

You can use an earlier action, request, to do whatever you need. It allows you to modify query variables, or even cancel the entire request without issuing a 404 error:

function wpse112929_cancel_request_parsing( $query_vars ) {
    if ( in_array( 'pagethatdontexist', $query_vars ) ) {
        return array();

    return $query_vars;
add_action( 'request', 'wpse112929_cancel_request_parsing' );

I used in_array() here instead of a direct comparison, because the actual match depends on your permalink structure. It would be name for /%postname%/, category_name for /%category%/%postname%/, pagename for /%year%/%monthnum%/%postname%/, etc.

You can also check $_SERVER['REQUEST_URI'] instead.

share|improve this answer

As someone (somewhere) said it's not a good idea to fall into a 404 without sending headers. The right way to do things is to redirect somewhere else.

If you fall into the 404 template, you'll have the 404 headers sent as logic as is. Search engines will also love you!


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.