Webstick.blog logo Wordpress, Design, SEO, Speed blog

How to create my own 404.php page [2024] 💥

How to create my own 404.php page


Not all themes have a 404.php file. What many people do is copy the 404.php file from another theme, but then the layout is not always perfect, your theme will have a different CSS. It is best to create your own file.


Advertisement

Divi Ad 680px


1. Creating a 404.php file

Copy the index.php file from your current theme to a file called 404.php does the trick. You will find the index.php on this location home/public_html/wp-content/themes/your-theme. Use a filemanager or FTP to get access to your hosting. You must delete all parts that are related to the WordPress loop. This is generally the section that starts something like this.


<?php if ( have_posts() ) : ?>

And ending with.


<?php endif; ?>

The syntax may be slightly different. However, you are looking for have_posts or endif. Next, insert the custom code below into the space that you have created.


<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: ".get_bloginfo('url'));
exit();
?>

This will redirect all 404 pages back to the homepage. Or use any other correct coding of course.

2. Using a plugin to create a 404.php file

We are going to use the "Smart Custom 404 error page" plugin. In your Wordpress backend go to "Plugins" >> "Add new" and search for the name of the plugin. Install and activate.

Just like any other page, you can create your own 404 error page with the WordPress Page Editor. Next, go to "Appearance" >> "404 Error Pages" and choose the page you created as your custom page. That's all!



Advertisement

Divi Ad 680px



Scroll up