Are there any hooks that alter the 404 logic?

After a bit more slogging through code and Googling, I found the answer. It’s contained in this thread (see Otto42’s post), but for the record, adding the following to your plugin will override the 404 handling for the conditions you specify:

add_filter('template_redirect', 'my_404_override' );
function my_404_override() {
    global $wp_query;

    if (<some condition is met>) {
        status_header( 200 );
        $wp_query->is_404=false;
    }
}

Note that you need to set “is_404” to false before PHP outputs headers, which is why hooking it in the template_redirect logic is a good idea.

~ Patch

Leave a Comment