404’s are part of every website. In WordPress, most themes has a
404.php template file and WordPress will automatically use that page if a Page Not Found error occurs.
In this post, I’ll show you how to redirect 404 page to any page in WordPress.
404.php file in your theme’s folder. If it doesn’t exist, then create a blank
404.php file. Paste the following code in there:
Here we are using php
header() function for the redirect and all 404’s will be redirected to homepage with the
get_bloginfo('url'). Change this to the page you want the 404’s be redirected to.
The first method lets you edit your theme template file and this is not always a best practice. So here we are going to get a more handy and general approach with a simple php snippet that you only need to put to your
Here we are using the
wp action hook to preform the redirect. Also remember to replace
get_bloginfo('url') with the page URL/function you want the 404’s be redirected to.