Do you want to redirect your 404 page to your home page in WordPress?
Redirecting the 404 ‘Not Found’ page to your website’s home page can help reduce your bounce rate and allow your users to discover other useful content on your website.
In this article, we will show you how to redirect your 404 page to your home page in WordPress.
Why Redirect Your 404 Page to Your WordPress Home Page?
When a user tries to visit a page that doesn’t exist on your WordPress website, WordPress will show them a 404 error page instead.
The wording and appearance of this page can vary depending on the theme you are using.
Most users who land on the default 404 page will leave your site quickly. This can increase your overall bounce rate and negatively impact your search engine rankings.
That’s why you should take the time to create a custom 404 page. However, until you do that, you can take the shortcut in this tutorial and redirect users to the homepage.
That being said, let’s look at how to redirect all 404 errors to your home page. We will cover two methods and also show you how to create custom redirects for individual pages:
Method 1: Redirect All 404 Errors to the Home Page in WordPress
For this method, we will be using All in One SEO for WordPress (AIOSEO). It is the best WordPress SEO plugin that allows you to set up redirects, optimize your content for search engines, and more.
The first thing you need to do is install and activate All in One SEO (AIOSEO). For more details, see our step-by-step guide on how to install a WordPress plugin.
Note: There is a free version of All in One SEO, but we will be using the Pro version since Redirect is a Pro addon.
Once the plugin is activated, you need to go to All in One SEO » Redirects.
If you haven’t set up redirects yet, then you must click the ‘Activate Redirects’ button.
This will install All in One SEO’s Redirects module.
Next, you will need to click on the ‘Settings’ tab at the top of the page. This page allows you to configure redirects in AIOSEO.
You need to scroll down the page until you find the ‘Advanced 404 Settings’ section. Enable this section by simply clicking the toggle button so that it turns blue.
Now you will be able to see some more settings. You should toggle the ‘Enable default 404 redirect’ button to the on position. After that, make sure that the ‘Home Page’ option is selected.
Notice that there’s also a ‘Custom URL’ option. This allows you to redirect 404 errors to any post or page. Don’t forget to click the ‘Save Changes’ button at the top or bottom of the page to store your settings.
Now when your visitors try to visit a URL on your website that doesn’t exist, they will be taken to the home page instead of seeing the default 404 page.
Method 2: Redirect All 404 Errors to the Home Page Using Code
If you prefer not to use a plugin, then you can use a simple code snippet to redirect all 404 pages to the homepage.
First, you will need to create a new file in your WordPress theme folder and name it 404.php. If your theme already has a 404.php file, then you must edit that file instead.
To edit this file, you need to connect to your WordPress hosting account with an FTP client or their file manager tool.
Once you are connected to your website, you will be able to see the 404.php file in your WordPress themes folder.
You need to add the following code as the first line in your 404.php file:
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: ".get_bloginfo('url'));
exit();
?>
Next, save the 404.php file and reupload it to your theme directory using FTP or your hosting control panel.
Now, when a page is not found, instead of seeing a 404 page, visitors will be redirected to your WordPress home page.
Bonus: Set Up Custom 404 Page Redirects With AIOSEO
The best and most SEO-friendly way of handling 404 errors is to redirect visitors to the most relevant page, not just your homepage.
The All in One SEO plugin’s Redirects feature can also track all 404-page errors and let you set up smart 404-page redirects in WordPress.
If you installed and activated AIOSEO when you followed Method 1, then all you need to do is navigate back to the All in One SEO » Redirects page and click on the ‘Settings’ tab.
Next, scroll down until you see the ‘Logs’ section. Your 404 logs are a record of URLs that your visitors have tried to use to visit pages that no longer exist on your site.
Make sure the ‘404 Logs’ is toggled on so that it looks blue. You can also choose how long you want the plugin to record your logs by selecting the time period from the dropdown menu.
Don’t forget to click ‘Save Changes’ before moving on.
After that, you can click the ‘404 Logs’ menu option to see the last accessed 404 page.
Remember, since you just enabled logging, it may not display anything right away. You might need to wait up to 24 hours before you see any useful insights there.
The ‘URL’ column will show you the pages users tried to visit but don’t exist.
You can redirect any of these URLs to an existing page by clicking the ‘Add Redirect’ link in the ‘Redirect’ column. This will open a dropdown where you can enter your redirect information.
For best results, you need to enter the most relevant page for the original query in the ‘Target URL’ box and then click ‘Add Redirect’.
For example, if you deleted a tutorial on how to start a WordPress blog and then wrote a new one, then it’s best to redirect that old URL to the new blog post rather than your homepage.
To add multiple 404-page redirects, simply follow the same steps as above.
Remember, generally, you don’t want to redirect your 404 page to your home page forever. It’s a great temporary solution until you create a custom 404 page design that will convert better or set up individual redirects that take users to a relevant page that does exist.
If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.
Do you want to improve your 404 page template in WordPress?
By replacing the default WordPress 404 page with your own design, you can improve the visitor experience and keep people on your site for longer.
In this article, we’ll show you how to customize your 404 page template in WordPress.
Why Improve Your 404 Page Template in WordPress?
Most WordPress themes come with a basic 404 template, including the default WordPress ones. For example, in the following image, you can see Twenty Twenty-Two’s 404 page.
However, most of these default templates are simple and don’t show any content from your site. This means that anyone who lands on your 404 page is more likely to leave your WordPress website, which will increase your bounce rate.
This is bad news for your WordPress SEO, and may affect where your site appears in the search engine rankings.
That being said, it’s a good idea to create a 404 page with your own content and branding.
For example, at WPBeginner we show a custom image and encourage visitors to contact us, so we can fix the 404 error. The sidebar also has links to our social media profiles and even some information about an ebook download.
Note: Even if you design an engaging and helpful page, you’ll still want to fix any 404 errors. Here, it helps to track your 404 pages and redirect them.
With that said, let’s take a look at how you can improve your 404 page template in WordPress.
Video Tutorial
If you’d prefer written instructions, just keep reading. You can also use the quick links below to jump straight to the method you want to use.
With this plugin, you can easily create a custom 404 page using a wide range of professionally-designed templates.
The first thing you need to do is install the SeedProd plugin. For more details, see our step-by-step guide on how to install a WordPress plugin.
Note: There is a free version of SeedProd available, but we’ll be using the Pro version since it lets you replace your theme’s built-in 404 template.
After activating the plugin, SeedProd will ask for your license key.
Once you’ve done that, go to SeedProd » Landing Pages. In the ‘404 Page’ section, click on ‘Set up a 404 Page.’
You can now choose a template for your 404 page.
To preview a design, simply hover your mouse over it and then click on the magnifying glass.
When you find a design that you like, just click on ‘Choose This Template.’
We’re using the ‘Oh No 404 Page’ template, but you can use any design you like.
After selecting a template, you’ll be taken to the drag-and-drop builder, where you can start customizing the 404 page.
On the left side of the screen, you’ll find blocks and sections that you can add to your design. The right side of the page is the live preview.
Most 404 templates already have some blocks, which are a core part of all SeedProd designs.
To customize any of these ready-made blocks, simply click to select the block in your layout. You can then customize the block using the settings in the left-hand menu.
To add a new block to your design, simply find the block in the left-hand menu. Then, drag it onto your layout. You can now customize the block following the process described above.
To start, you’ll typically want to add your own website logo to the 404 page.
To replace the SeedProd logo with your own branding, simply click to select the placeholder logo in your layout. Then, hover over the image in the left-hand menu and click on the ‘Select Image’ button.
This launches the WordPress media library, where you can select any image or upload a new file from your computer.
Many 404 templates also display your site’s main navigation menu by default. If you have multiple menus, then you may prefer to show a different menu instead.
To make this change, simply click on the ‘Nav Menu’ block in your template. You can then open the ‘Menu’ dropdown and choose any menu from the list.
You can create any design simply by adding and customizing blocks. However, when someone arrives at your 404 page, they may be confused about what to do next.
With this in mind, we’ll show you how to promote your most popular posts and create a contact form, so visitors can report any broken links or missing content.
To start, add a ‘Headline’ and a ‘Text’ block to your design. You can then type your message into the text editor in the left-hand menu.
For example, in the following image, we’ve created a headline that explains the page can’t be found and a ‘Text’ block that suggests reading some posts or using the contact form.
Next, we’re going to change the ‘Back To Home’ button so it encourages people to check out a particular post instead of going to the general homepage.
To customize the button, simply click to select it in the page layout. Then, type the post’s URL into the ‘Link’ field.
To change the text that appears on this button, simply type into the ‘Button Text’ box.
Once you’ve done that, click on the ‘Advanced’ tab. Here, you can change the button’s color, size, and more.
Add Your Most Popular Posts to Your WordPress 404 Page
Next, you can add a list of your most popular posts to the 404 page. Since these articles are popular, there’s a good chance visitors will find something they like.
After activating MonsterInsights, you can display your most popular posts by adding shortcode in WordPress. In SeedProd’s left-hand menu, simply find the ‘Shortcode’ block and drop it onto your layout.
Then, click to select the ‘Shortcode’ block. This will open the settings window to the left. Next, copy the following shortcode:
Then, in the box labeled ‘Content,’ paste it into the text area labeled ‘Shortcode.’
By default, SeedProd doesn’t show a preview of your most popular posts inside the page editor, so you’ll need to click on the ‘Preview’ button in the upper-right corner. This opens your design in a new tab.
If you prefer to preview the popular posts list inside the page editor, then simply click on the ‘Show Shortcode Preview’ switch.
In the above shortcode, we’re using theme=“beta†for our list, but MonsterInsights has a few different themes that you can use.
To see the different themes, go to Insights » Popular Posts in the WordPress dashboard and then click on ‘Popular Posts Widget’.
You can now click on the different themes to see a preview.
When you find a design that you want to use, simply update the shortcode in SeedProd. For example, if you want to use the ‘Alpha’ theme then you would need to type in:
You may also want to add a contact form so visitors can reach out if they can’t find what they’re looking for. This form also gives people an easy way to report broken links, so you can fix them and improve the experience for future visitors.
The best way to add a contact form to your site is by using the WPForms plugin. It’s the best contact form plugin for WordPress and comes with a user-friendly drag-and-drop form builder.
Once you’ve created a contact form, it’s easy to add that form to your 404 page. Simply find the ‘Contact Form’ block and drag it onto your design.
Then, open the ‘Select a Form’ dropdown and choose your contact form from the list.
The page editor will now show a preview of the contact form.
You might want to add some text introducing your contact form or encouraging visitors to get in touch.
To do this, simply add a ‘Headline’ or ‘Text’ block above your contact form and then type in the text that you want to use.
When you’re happy with how the 404 page looks, it’s time to publish it.
Simply click the dropdown arrow next to ‘Save’ and then select ‘Save as Template.’
When asked, go ahead and type in a name for the template. This is just for your reference so you can use anything you want.
After that, click on ‘Save Template.’
In the next popup, click on ‘Return to Page Editor.’ You can then click on the ‘X’ button in the upper-right corner to close the SeedProd page editor.
At this point, you may see a popup asking whether you want to publish your new 404 design. If you’re happy to go ahead, then click on ‘Yes, Activate.’
If you don’t want to publish the template right now, then click on ‘No, Close’ instead.
After that, you can publish the design at any point by going to SeedProd » Pages. Here, click on the switch in the ‘404 Page’ section so it shows ‘Active.’
To see your 404 page in action, just add /404 to the end of your domain name.
After publishing your custom 404 page, it’s a good idea to track how people are engaging with that page. This allows you to see what’s working and what isn’t working, so you can fine-tune your 404 design to get more conversions and engagement.
Method 2. Create a Custom 404 Page in WordPress By Adding Code
If you don’t want to use a page builder plugin, then you can create a custom 404 page using code. However, just be aware that any mistakes in your code can cause common WordPress errors, or even break your site.
With that in mind, this method isn’t recommended for beginners. It’s also a good idea to back up your site before using this method, just in case you encounter any problems.
After connecting to the server, go to /wp-content/themes/ and then open the folder for your current WordPress theme.
If this folder already has a 404.php file, then you can go ahead and open that file in any text editor, such as Notepad.
If your theme doesn’t have a 404.php file, then you’ll need to create one. After that, go ahead and open the file in a text editor app.
You’re now ready to create a custom 404 design using code. You can create all sorts of designs, but here’s some simple examples to help you get started.
Display Most Popular Posts on 404 Page
A list of your most popular posts can encourage visitors to check out your site’s best content.
First thing you need to do is install and activate the WordPress Popular Posts plugins. For more details, see our step by step guide on how to install a WordPress plugin.
Upon activation, you can add a list of popular posts to your 404 page using the following template tag:
<?php wpp_get_mostpopular(); ?>
Display Most Commented Posts on 404 Page
This plugin can also display the posts that have the most comments.
In your 404.php file, simply find the area where you want to show your most commented posts, and then add the following template tag:
Another option is to show your site’s most recent posts. This can be particularly effective if you post time-sensitive blogs, for example if you run a news aggregator website.
There are several different ways to display recent posts in WordPress, but the easiest way is adding a template tag to your 404.php file:
If you have lots of content, then it may be impossible to show all those posts on your custom 404 page.
One option is to organize your content into monthly archives. Visitors can then click to explore content from different months and years.
Here at WPBeginner, we display our monthly archives on our 404 page using the Compact Archives plugin. This helps visitors browse all of our content, without overwhelming them with a long list of posts.
If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.