Reputation: 13
In WordPress I modified my 404 page so this page display feed based on what user types In url.
So if he types mywebsite.com/orange
and I don't have this page on website, my script will search for orange
and search results and article will be displayed on 404 page.
However, I was banned from Adwords Campaign because my website return to many 404 errors.
How can I disable 404 status in 404.php page, so Google will not think that /orange/
is 404. I want 404.php to be just like a layout. ( So technically my website can't have 404 ).
Upvotes: 1
Views: 353
Reputation: 2362
You should be able to do that by filtering the header as it is set. Something like this would prevent all 404 headers from ever being sent.
function theme_block_404($header, $code, $description, $protocol)
{
if (intval($code) === 404) { //Is this a 404 header?
$description = get_status_header_desc(200); //Get the default 200 description
return "{$protocol} 200 {$description}"; //Return a 200 status header
} else { //This isn't a 404 status
return $header; //Don't change the header
}
}
add_filter('status_header', 'theme_block_404');
Keep in mind that this is a bit of a cudgel in that it prevents any 404 error from ever being thrown. If that is appropriate for your situation, great, otherwise, you may want to add additional logic to this function to make it more specific in scope.
Upvotes: 1