wordpressserverhttp-status-code-404

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?


Solution

  • 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!