WordPress 410 Status Code for 404 Pages

This file contains a WordPress function that changes the HTTP status code from 404 to 410 for pages that are not found. It's designed to inform search engines that the content is permanently removed, potentially improving SEO by preventing indexing of non-existent pages.

<?php /** * Sets the HTTP status code to 410 for 404 Not Found pages. * * This function checks if the current request resulted in a 404 error and, if so, * sets the HTTP status code to 410 (Gone). It should be attached to the 'template_redirect' action hook. */ function cwpai_set_410_for_404_pages() { if (is_404()) { status_header(410); nocache_headers(); } } add_action('template_redirect', 'cwpai_set_410_for_404_pages');

Frequently Asked Questions

The code sets an HTTP status code of 410 for pages that are not found (404) on a WordPress site.