How To Create A Custom 404 Page In WordPress?

A 404 error page is displayed when a user tries to access a page on your website that doesn’t exist. By default, WordPress comes with a basic 404 error page. However, you can create a custom 404 error page to improve the user experience and keep visitors on your site.

To create a custom 404 page in WordPress, follow these steps:

Create a new page or post: First, create a new page in WordPress dashboard by navigating to Pages > Add New Page in the WordPress dashboard.

Add content: On the new page, add the content you want to display when a user lands on a 404 error page. This could include a message explaining that the page they are looking for doesn’t exist, links to popular pages on your site, or a search bar to help them find the information they need.

Save the page: Once you have added the content, save the page.

Set the page as the 404 page: Next, you need to set the new page as the 404 page. You can do this by installing and activating a plugin like “404page” or by adding code to your theme’s functions.php file.

To use the “404page” plugin, install and activate it, then navigate to Settings > 404 Error Page in the WordPress dashboard. Choose the page you created as your custom 404 page.

Alternatively, you can add code to your theme’s functions.php file to set the custom page as the 404 page. Here’s an example code snippet:

Copy code
function
custom_404_page() {
if (is_404()) {

$custom_404_page = get_permalink(‘your-custom-404-page-id’);
wp_redirect($custom_404_page);
exit;
}
}
add_action(‘template_redirect’, ‘custom_404_page’); Replace “your-custom-404-page-id” with the ID of the page you created, then add the code to your theme’s functions.php file.
Once you have set the custom page as the 404 page, visitors who land on a page that doesn’t exist will be redirected to your custom 404 error page.
×