To create a custom 404 error page in WordPress, you can follow these step-by-step instructions:
1. Access your WordPress website’s files: You can do this through an FTP client or by using the file manager provided by your hosting provider.
2. Locate your WordPress theme directory: Navigate to the `/wp-content/themes/` directory in your WordPress installation.
3. Create a child theme (optional): It’s recommended to create a child theme if you’re not already using one. This way, you can make changes without modifying the parent theme directly. If you already have a child theme, skip this step. To create a child theme, create a new directory inside the `/wp-content/themes/` directory and name it something like “my-child-theme”.
4. Create a new file for your custom 404 page: Inside your theme directory (or child theme directory if you’re using one), create a new file and name it `404.php`. This filename is important because WordPress will automatically use it for handling 404 errors.
5. Open the `404.php` file in a text editor: You can use any text editor you prefer, such as Notepad, Sublime Text, or Visual Studio Code.
6. Add the HTML and PHP code for your custom 404 page: Customize the appearance and content of your 404 error page using HTML and PHP. You can include a message, links to popular pages, search form, or any other elements you want. Below is a basic example of a custom 404 page:
<?php get_header(); ?>
<h1>404 – Page Not Found</h1>
<p>Oops! The page you are looking for does not exist.</p>
<p>You can try searching for the content using the search form below:</p>
<?php get_search_form(); ?>
<?php get_footer(); ?>
7. Save the `404.php` file: Once you’ve finished customizing your 404 error page, save the file.
8. Upload the file to your theme directory: If you created a child theme, upload the `404.php` file to the child theme directory. Otherwise, upload it directly to your theme directory, replacing the existing `404.php` file if it exists.
9. Test your custom 404 page: To test the custom 404 page, visit a non-existent page on your website (e.g., `http://yourdomain.com/non-existent-page`). You should see your custom 404 page instead of the default server-generated 404 error page.
That’s it! You have successfully created a custom 404 error page for your WordPress website. You can further customize it by adding CSS styles or additional functionality based on your needs.