How to return a 410 Gone status in WordPress

WordPress answers every missing URL with 404 and has no setting for 410. To return 410 Gone for content you deleted deliberately, either change the status in PHP with status_header( 410 ) on a list of paths, or declare the paths gone in Apache or nginx so the server answers before WordPress runs.

A 410 says the page existed and has been removed permanently. A 404 says only that nothing is at the address. Use 410 for a deliberate, final removal with no replacement page.

Step by step

1. Decide between redirect, 404 and 410

  • Something replaces the page: 301 to that page. Not a 410.
  • Nothing replaces it and you removed it on purpose: 410 is the most precise answer.
  • You are not sure, or it may come back: leave the 404.

Google's documentation groups 404 and 410 together: both tell it the page is not available and both lead to the URL being dropped from the index. The practical gain from 410 is clarity for you and for other crawlers, not a ranking effect. If setting it up is awkward on your host, a 404 does the job.

2. List the paths

Write down the exact paths, with the trailing slash style your site uses, for example /summer-sale-2024/ and /discontinued-widget/. For a whole section, note the prefix, such as /old-forum/. Check each in Search Console's Performance report first. A URL that still earns clicks or has links from other sites deserves a redirect to something relevant instead.

3. Option A: return 410 from WordPress

Add this to a small plugin or your child theme's functions.php:

php
add_action( 'template_redirect', function () {
    if ( ! is_404() ) {
        return;
    }
    $gone = array( '/summer-sale-2024/', '/discontinued-widget/' );
    $path = trailingslashit( (string) wp_parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH ) );
    if ( in_array( $path, $gone, true ) || str_starts_with( $path, '/old-forum/' ) ) {
        status_header( 410 );
        nocache_headers();
    }
} );

It only acts on requests WordPress already treats as not found, swaps the status to 410, and lets the theme's 404 template render as usual. Visitors see your normal error page. Crawlers see the 410. Delete or trash the content first, since a published post at the path is not a 404.

4. Option B: return 410 from the server

Apache or LiteSpeed, in .htaccess above # BEGIN WordPress:

apache
Redirect gone /summer-sale-2024/
RedirectMatch gone ^/old-forum/

nginx, inside the server block:

nginx
location = /summer-sale-2024/ { return 410; }
location ^~ /old-forum/ { return 410; }

The server answers without loading WordPress, which is faster and suits large removed sections. The trade-off is the response body: visitors get the server's bare "Gone" page unless you configure a custom error document.

5. Verify the status

bash
curl -sI https://example.com/summer-sale-2024/ | head -1

Expect 410. Then confirm a normal page still returns 200 and an unrelated missing URL still returns 404, so you know the rule is not too broad.

6. Remove the URLs from everything you control

A gone page should not be advertised. Remove it from menus, delete internal links to it, and check the XML sitemap. WordPress and Hydrogen SEO sitemaps list only published content, so a deleted post drops out by itself. A hand-written sitemap or custom link list will need editing.

7. Watch the reports

In Search Console's Pages report, URLs answering 410 are listed under Not found (404) or the general 4xx group. That is expected, and they fade out of the report over time. There is no need to mark anything as fixed.

What the plugin covers

Hydrogen SEO's Redirection Manager creates 301 and 302 redirects, not 410 responses, so the status itself comes from the snippet or the server. The plugin helps with the decision before it: the 404 Monitor shows which missing URLs are still being requested, how often and from which referrer. Paths with steady hits from real pages are better redirected. Paths requested only by bots are fair candidates for a 410.

Mistakes to avoid

  • Sending 410 for a page that moved. You discard its links. Redirect it.
  • A prefix that is too short. ^/old also matches /older-posts/. Anchor patterns and end them with a slash.
  • Leaving the rule after republishing. If content returns to that path, remove the path from the list, or visitors get a 410 on a live page from the server rule.

Common questions

Is 410 better than 404 for SEO?

Not measurably. Google treats both as "not available" and drops the URL. 410 is the more accurate signal for a deliberate, permanent removal.

Can WordPress return 410 without code?

Core has no setting for it. You need a snippet, a server rule, or a plugin that offers a 410 response type.

Should deleted blog posts return 410?

Only if nothing replaces them and they have no links or traffic worth keeping. Otherwise redirect to the closest related post.