twrld1
twrld1

Reputation: 43

Wordpress change all 404 to 410 error code

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

Answers (4)

Kevin Benabdelhak
Kevin Benabdelhak

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

Roniz Shakya
Roniz Shakya

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

Pedro Vasconcelos
Pedro Vasconcelos

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

Raunak Gupta
Raunak Gupta

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.

  1. Create a Page form WordPress Admin panel as Error 410 (or with any name of your choice)
  2. Write your content in that page which you want to show to the user.
  3. After publishing the page you can get the page ID from the URL
  4. Add the given code in your active theme 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

Related Questions