How to add 404 Error Page Redirection in WordPress website

Adding a 404 redirection in WordPress can significantly improve your website’s usability, user experience, and SEO. If you have a WordPress website, you should create a 404 redirection in your website because:

  • 404 Redirection Can Enhance User Experience
  • Improves SEO
  • Reduces Bounce Rate
  • Fixes Broken Links
  • Prevents Lost Conversions
  • Make Your Website More Professional

In this article, we will introduce how to add 404 redirections to your WordPress site.

Method 1: Using a Plugin (Easy and Recommended)

  1. Install the “All 404 Redirect to Homepage” Plugin:

    • Go to your WordPress dashboard and navigate to Plugins > Add New.
    • Search for All 404 Redirect to Homepage.
    • Install and activate the plugin.
  2. Configure the Plugin:

    • After activation, go to Settings > All 404 Redirect to Homepage.
    • Enable the plugin and choose the page where you want to redirect (e.g., Homepage or a Custom Page).
    • Save the changes, and all 404 errors will be automatically redirected to the page you selected.

Method 2: Using Custom Code (Manual Approach)

You can also manually add code to your theme’s functions.php file to redirect 404 errors.

  1. Add Code to functions.php:

    • Go to your WordPress dashboard, navigate to Appearance > Theme File Editor.
    • Open your theme’s functions.php file.
  2. Add the Following Code:

				
					function redirect_404_to_home() {
    if (is_404()) {
        wp_redirect(home_url());
        exit();
    }
}
add_action('template_redirect', 'redirect_404_to_home');

				
			
  1. This code checks if a 404 page is encountered and redirects the user to the homepage.

  2. Save the Changes:

    • After adding the code, click Update File to save the changes.

Method 3: Using .htaccess (For Advanced Users)

If you have access to your server’s .htaccess file and are comfortable with server configuration, you can create 404 redirects at the server level.

  1. Access .htaccess:

    • Use an FTP client or your hosting control panel to access the .htaccess file in the root directory of your WordPress installation.
  2. Add the Redirect Rule: Add the following rule at the bottom of your .htaccess file:

				
					ErrorDocument 404 /index.php

				
			
  1. This will redirect all 404 errors to your homepage or another page as specified by /index.php.

  2. Save the Changes:

    • Save the .htaccess file and upload it back to the server.

Method 4: Redirect to a Custom 404 Page

If you don’t want to redirect to the homepage but a custom 404 page, here’s how to do it:

  1. Install a Plugin Like “404page”:

    • Go to Plugins > Add New and search for the 404page plugin.
    • Install and activate the plugin.
  2. Create a Custom 404 Page:

    • Go to Pages > Add New and create a custom 404 page with content you’d like to display.
  3. Set the Custom Page:

    • Go to Appearance > 404 Error Page.
    • Select the custom 404 page you created.

This way, instead of an auto-redirect, users will see a customized 404 page.

Conclusion

  • Plugins: Use All 404 Redirect to Homepage for easy setup.
  • Custom Code: Add the code snippet to functions.php for manual control.
  • Server-Side: Use .htaccess for server-level redirection.
Scroll to Top