What is the error 404?
The error 404 is a message shows up if you click on a link that doesn’t work (anymore) or if you typed wrong Url. This is default in WordPress but some themes don’t come with a 404.php file.
Basic Error 404 Template
If you do not have default 404.php page, you can create it. Create a 404.php file with the below code..
The above code would give a simple “Error 404 – Page Not Found.” as ouptput, which is mentioned within in h2 tag. You need to modify header, sidebar & footer as per your theme structure.
404 page with Search Form
Want to add search form to help users stick around instead of leaving. By this way visitors have the option of searching your site, even if lands on your 404 page. If you want to add search form for your 404 page, add the below code..
404 page redirect to home page
If you want to just redirect 404 page to home page then add the below code in 404.php
Make it more dynamic
If you want to create a more dynamic error 404 page you can use this way so that the visitor only sees the brief error and, then gets redirected to your home page. This page can be made to be somewhat SEO friendly. For this you need to edit the header.php file of your template. Within the meta tags at the top of your header.php file add the below code ..
After added it into header.php file, you need to edit your 404.php file to look like this:
This above example will allow the user to land on your 404 error page and then automatically take them to the home page. This will also help users stick around instead of them being left confused and leaving your website. Please make sure to replace home or template url with the exact link where it should redirect.