What is a 404 error and why does my website need a 404 error page?
The 404 is a HTTP standard response code which indicates that the client was able to communicate with the server but the server could not find what was requested.
If the server does not send a page to be displayed together with the error code the browser shows a default error message, which looks different depending on the used webbrowser.
You can’t avoid 404 errors on your site so it should be needless to say your site should have a custom 404 error page fitting your design instead of showing your visitors a more or less ugly browser error message.
WordPress and 404 error pages
WordPress comes with a built-in feature to deliver a 404 error page when an 404 error occurs. To enable this feature the only thing you have to do is to change the Permalink Structure to anything else but ‘Plain’. As long a you leave this setting to ‘Plain’ the 404 errors are not handled by WordPress but by the webserver.
Creating a custom 404 error page for your WordPress driven site
In WordPress the 404 error page is part of the Theme. Normally you’d need programming skills to create a custom 404 error page. This plugin allows you to create and edit your custom 404 error page as a normal page using the full power of WordPress and making use of all installed pluings and available shortcodes. Plus you can also use your favorite page builder.
The 404page plugin does not redirect your browser to the given page. That’s important because it ensures that a correct code 404 is delivered. This tells search engines that the page does not exist and has to be removed from the index. A redirect would result in a HTTP code 301 or 302 and the page would remain in the search index.
Page to be displayed as 404 page
Select the page you want to be displayed as your custom 404 error page from the dropdown list. You first have to create the page from the ‘Pages’ menu.
The ‘Edit Page’ button allows you to edit the selected page directly from here. The ‘Test 404 error’ button opens a page with a randomly generated URL which should cause an 404 error. If you select a different page both buttons are disabled and you have to save the settings to enable them again.
Hide the selected page from the Pages list
Activating this option hides the page you selected as custom 404 error page from the ‘Pages’ menu for non admin users. For admin users it’s always visible. The page selected as 404 page is marked.
Send an 404 error if the page is accessed directly by its URL
This option is activated by default and it is recommended not to change this setting. With this option active WordPress fires an 404 error in case the page you selected as your custom 404 error page is accessed directly by its permalink. The only reason to deactivate this option is if you explicitly want the page to be accessible.
WP Super Cache Compatibility
If you are using the WP Super Cache plugin for caching also the page you defined as your custom 404 error page will be cached and WP Super Cache will always send a HTTP code 200 and not a 404. To avoid this behavior you have to exclude the page from caching. If the 404page plugin detects the WP Super Cache plugin it will show you a message hereof. This may also relate to other caching plugins.
Force 404 error after loading page
After an 404 error occurred the 404page plugin loads your custom 404 error page. After that page is loaded successfully the 404 error is gone. Naturally the 404page plugin ensures, that a 404 error is sent back to the browser. But WordPress internally the error no longer exists.
This is stringently required because otherwise WordPress above all would load the default 404 error page. If you essentially need the WordPress internal information that an 404 error occurred, this feature forces an 404 error after loading your custom 404 error page. For instance this is required if you use the 404 Detection of the iThemes Security plugin. With this feature activated, the 404page plugin generates an 404 error after WordPress cleared the error once the custom 404 error page was loaded. The 404 error internally is available inside the WordPress header (
wp_head). It is not available outside the header to ensure that the page displays properly. This potentially may cause problems with your theme or with other plugins, so please activate this feature only if necessary and extensive test if everything works.
Disable URL autocorrection guessing
Maybe you’ve never noticed the URL Autocorrect Guessing feature of WordPress yet. WordPress tries to guess a redirection for a nonexistent URL if the slug is at the beginning of another URL. The downside ist that WordPress is not exactly good at guessing URLs and often times makes the mistake of redirecting users to unmatched content.
Plus it generally is not a good idea to have automated redirects that are out of your control. In my opinion getting 404 errors is much better than automatic guessing.
This feature stops WordPress from guessing and automated redirecting. If you activate this feature links that worked in the past may work no more, because they are wrong all along and only worked due to the WordPress URL autocorrection guessing.
Send an HTTP 410 error instead of HTTP 404 in case the requested object is in trash
Activating this option has no visual effect. This will cause WordPress to send an HTTP 410 error code instead of an HTTP 404 error code in case the URL that was requested belongs to an object that is currently in trash.
The HTTP 410 response header can be used when a resource has been permanently removed. It informs search engines that the resource requested is no longer available and will not be available again so it can be removed from the search index immediately.
However search engines do not delete URLs from their index the very first time it responds with HTTP 410. But indeed they handle 404 and 410 errors slightly different. Sending a 410 response header should cause a much faster removal than sending a 404 response.
By default WordPress keeps objects in trash for 30 days and permanently deletes them after that. This should be enough time for search engines to drop deleted pages from their index. After an object is deleted permanently, which means it is no longer in trash, trying to access it will result in an HTTP 404 error as usual.
Activate Compatibility Mode
The 404page plugin uses the WordPress Template System to detect and handle 404 errors. Some plugins and themes bypass this task, thus the 404page plugin does not work properly.
In such cases try to activate Compatibility Mode, which uses its completely own method to detect and handle 404 errors. This maybe can solve incompatibility with your theme or another plugin. Only activate Compatibility Mode if the 404page plugin does not work properly. Otherwise it makes no sense at all.
Special Operating Methods
If the 404page plugin detects that you are using the WPML plugin (the 404page plugin is officially certified as WPML compatible by the WPML team) or the Customizr theme it automatically switches to a specific adapted mode to achieve best compatibility.
A theme can activate the native mode to fully control the 404page plugin.
Note about XML sitemaps
If you use a plugin to generate a XML sitemap, then it is recommended to exclude your custom 404 error page so that it is not transmitted to search engines.
If you are using the XML sitemap feature of Yoast SEO the 404 page is excluded automatically, you don’t have to exclude it manually.
The plugin adds a CSS class
error404 to the
<body> HTML tag. You can use this class for extra styling.
The plugin adds an action hook
404page_after_404 which you can use to add extra functionality. The exact position the action occurs after an 404 error is detected depends on the Operating Method. Your function must not generate any output. There are no parameters.
Native theme support
As a theme developer you can activate a special native mode to fully control the 404page plugin.
If the 404page plugin is installed and activated it defines the PHP constant
PP_404. Check existence of it to detect the 404page plugin.
pp_404_is_active() functions returns
true if there is a custom 404 page selected in the plugin’s settings and the selected page exists. Otherwise it returns
pp_404_set_native_support() function to activate native mode. If native mode is activated the 404page plugin does not generate any output. Independently, the
error404 CSS class is added to the
<body> tag anyway.
pp_404_get_the_title() function retrieves the title of the custom 404 error page, like
get_the_title(). It accepts no parameters.
pp_404_the_title() function displays the title of the custom 404 error page, like
the_title(). It accepts no parameters.
pp_404_get_the_content() function retrieves the content of the custom 404 error page, like
get_the_content(). It accepts no parameters.
pp_404_the_content() function displays the content of the custom 404 error page, like
the_content(). It accepts no parameters.
Important advice: This sample code just illustrates how the native mode works. The
pp_404_set_native_support() function must not be used inside a template file. You have to call it in the
functions.php file of your theme immediately. This ensures that the Operating Method setting is deactivated on the settings page and a message is shown that native mode is active.