Reputation: 43
My wordpress site has nearly 3000 posts that was deleted recently. Instead of showing error code 404, How do I show error code 410 to all deleted or not found posts and pages?
Upvotes: 4
Views: 9519
Reputation: 66
This might not be a good idea. A 404 page means the page doesn't exist and can show up at any time on your site.
Search engines like Google can create a 404 if there's a user signal to a URL, even if the page doesn't actually exist on your site.
Sending a 410 response to all your 404 pages can harm your crawl budget.
You need to export your URLs from Google Search Console as a CSV file. This plugin can help you import these URLs and change them to 410: https://kevin-benabdelhak.fr/plugins/wp410/
Remember, Google checks 410 pages often and over a long time. You shouldn't change all 404 pages, just the ones from your deleted articles.
Upvotes: 0
Reputation: 11
On the chrome browser the above code was not working like in other browsers.I modified the above code to the code below. Now the 404 errors directs to the 410 page. I guess this is how it supposed to work. Do notify me if there are an mistake in the code i edited?
$custom_410_page_ID = 2242;//Error 410 page ID
header($_SERVER["SERVER_PROTOCOL"] . " 410 Gone");
header("Location: " . get_permalink($custom_410_page_ID));
exit();
Upvotes: 1
Reputation: 111
you don't need to create a page. just add this code before the get_header(); in you 404.php template
header($_SERVER["SERVER_PROTOCOL"] . " 410 Gone");
Hope this helps!
Upvotes: 6
Reputation: 10799
You can either use this plugin which will come handy for you, or you can follow the given steps to achieve this without using any plugin.
404.php
file.Code for 404.php
$custom_410_page_ID = 25;//Error 410 page ID
header($_SERVER["SERVER_PROTOCOL"] . " 410 Gone");
header("Refresh: 0; url=" . get_permalink($custom_410_page_ID));
exit();
Now when any on visit your old URL or mistype any URL it will be redirected to Error 410 page with 410 status code to .
Reference: Move All 404 To 410
Hope this helps!
Upvotes: 2