How to Force 404 Errors in WordPress (and Use 410 for Deleted Pages)

Sometimes you need to force 404 errors in WordPress. Maybe you deleted thin or spammy pages, or old URLs with bad backlinks, and want search engines to drop them. When I deleted URLs with bad backlinks to recover from a Google penalty, I found the unpublished pages still returned a 200 OK status. Here is how to make sure removed pages really return a 404 (or better, a 410) in WordPress in 2026.

Force 404 errors in WordPress

Quick answer: Trash or delete the post, then purge your page cache and CDN, and check the URL’s status code with an HTTP header checker or curl -I. If it still shows 200, use Rank Math’s or the Redirection plugin’s option to return 410 Content Deleted (or 404) for that URL, or add a small template_redirect snippet that sends a 404 status.

404 vs 410: which should you use?

  • 404 Not Found: the page does not exist. Google drops it after recrawling a few times.
  • 410 Gone: the page was removed on purpose. Google treats it as a slightly stronger signal and usually drops it faster.
  • 301 Redirect: use this instead if a better page on the same topic exists, to keep visitors and link value.

Learn more about HTTP 410 error pages.

Why WordPress may not return a 404

  • Cached pages: LiteSpeed Cache, WP Rocket or a CDN can keep serving the old page with 200 OK until purged.
  • Redirect plugins: some plugins redirect every 404 to the homepage, which Google treats as a “soft 404”.
  • Attachment and archive pages: an image attachment or tag page may still exist for the old content.
  • Theme 404 template: a custom 404 page that returns 200 instead of 404.

How to force a 404 or 410 in WordPress

Method 1: Rank Math Redirections

In Rank Math > Redirections, add the old URL as the source and choose 410 Content Deleted (or 451) as the type. No destination is needed.

Method 2: Redirection plugin

Add a redirect for the URL and choose the action “Error (404)” or “Error (410)”.

Method 3: A code snippet

add_action( 'template_redirect', function () {
    $gone = array( '/old-page/', '/another-old-post/' );
    if ( in_array( $_SERVER['REQUEST_URI'], $gone, true ) ) {
        global $wp_query;
        $wp_query->set_404();
        status_header( 404 );
        nocache_headers();
        include get_query_template( '404' );
        exit;
    }
} );

Check that it worked

  1. Purge your cache plugin and CDN.
  2. Run curl -I https://example.com/old-page/ or use an online HTTP header checker. You should see 404 Not Found or 410 Gone.
  3. In Google Search Console, inspect the URL and check the Pages report for “Not found (404)”.

Clean up after removing pages

FAQ

Are 404 errors bad for SEO?

No. 404s for pages that should not exist are normal. Only fix 404s for pages that should be live or have valuable links.

How long does Google take to drop a 404 page?

Usually days to weeks, depending on how often Google crawls your site. 410 can be slightly faster.

What is a soft 404?

A page that says “not found” but returns 200 OK, or redirects to an irrelevant page. Google reports these in Search Console.

Have you pruned old content on your site? Share your results in the comments.

Stuck on a gift? Try our free Gift Idea GeneratorIdeas for anyone by age, job, interests and budget, with Amazon.com and Amazon.in linksFind gifts →

Found this useful? Share it with someone who needs it.

Get our free weekly email: new tech guides and tools, no spam.

New and updated tech guides, a free tool worth bookmarking and one useful pick, once a week. No spam, unsubscribe anytime.

One email a week. Unsubscribe anytime. See our privacy policy.

Related Tech Guides

Leave a Reply

Your email address will not be published. Required fields are marked *

16 Comments

  1. I don’t think 404 errors make any difference in website rankings. I think stressing too much on 404 is like wasting time.

  2. Nice Article , Thanks for sharing useful tips with us. I am new blogger so i am very thankful for your article

  3. Wow. Thanks for this information. Putting 404 errors in wordpress helps to solve this problem of penalizing. Thank you.

  4. thanks for this wonderful blog. it is very helpful to others who spend there priceless time in searching solution for this.

  5. I am not a technical guy and due to this I was facing some problem to fix 404 not found error in my blog. I followed your tips and now all errors have been fixed. Thanks to share such useful tips with us.

  6. It’s normal to get 404 error. When we get these errors at a greater extent then it will create problem because we can get penalized by Google. I was also seeking for the solution. How to fix it? You have provided such a useful information about fixing 404 error. Thanks for the post.

  7. Hello,

    I have WordPress website and would not find 404 errors but your article was very helpful not only it guided me but also help me to use right code.

    Thanks

  8. I used Permalink Validator to solve some of the issues that I had with wrong URLs typed but the most annoying problem still remains.

    When someone clicks on a link to my blog that ends with /?something like ?download_free_movies it still directs them to a page on my blog and I would like them to see a 404 not found page instead.

    My wordpress website was recently hacked and I have hundreds of those links listed on google and other search engines and websites. I am in the process of trying to remove them from google cache but returning a 404 instead of directing it to a page on my website would be very helpful as well.

  9. Yes I can hit pretty much all other files without problem. I’m assuming if there’s another PHP file with similar naming convensions the same would happen (ie somefile.js.php or somecss.css.php ) I’m turned off the pretty URL rewriting and it seems to have fixed the 404 but I don’t get the nice permalink structure.

  10. This post is very worthy for me. A great my problem is solved by this post. Thanks

  11. Hi… First test the exact location of the file in your browser to see it loads. Then you can add the following code on top of your WordPress folder .htaccess file to let it find the file.thank you for the share..

  12. 404 errors are killing one of my clients websites because they removed a bunch of pages before consulting me. now I have to manually go through and create redirects.

  13. Yea you are right sometimes will get penalized so forcing 404 in wordpress is a great idea.Thanks for sharing this idea with us!