# Return 410 Gone for Removed Pages

> Answers requests for pages you deleted on purpose with a "410 Gone" status instead of a 404, so search engines drop them from results faster.

- Type: PHP
- Runs: Run everywhere
- Category: [Redirects](https://wpide.com/library/category/redirects/)
- Tags: redirects, 410, seo
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/gone-410-for-removed-urls/

## Code

```php
// Addresses you removed on purpose and that will not come back. Empty = off. A trailing * matches everything below. Examples:
// '/old-promo/',
// '/discontinued-products/*',
$wpide_gone_paths = array();

add_action( 'template_redirect', function () use ( $wpide_gone_paths ) {
    // Only for addresses that are missing anyway, so live content can never be hidden by mistake.
    if ( ! $wpide_gone_paths || ! is_404() ) {
        return;
    }

    $path = isset( $_SERVER['REQUEST_URI'] ) ? strtolower( (string) wp_parse_url( wp_unslash( $_SERVER['REQUEST_URI'] ), PHP_URL_PATH ) ) : '';

    foreach ( $wpide_gone_paths as $gone ) {
        $gone = strtolower( (string) wp_parse_url( home_url( $gone ), PHP_URL_PATH ) );

        $match = '*' === substr( $gone, -1 )
            ? 0 === strpos( $path, rtrim( $gone, '*' ) )
            : untrailingslashit( $gone ) === untrailingslashit( $path );

        if ( $match ) {
            // 410 tells search engines the page is gone for good, so they drop it faster than a 404.
            status_header( 410 );
            nocache_headers();
            header( 'X-Robots-Tag: noindex' );
            return;
        }
    }
} );
```

## Notes

The list is empty by default; only addresses that are already missing get the 410, so live content is never hidden.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Return 410 Gone for Removed Pages" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
