NB: Make sure you do a back up of your theme, files and database before attempting the tutorials
Easy
Last modified : Dec 24 2022
Estimated reading time : 0 minutes, 47 seconds - 74 words
Share the post "Redirecting 404 Pages"
Redirecting 404 pages: There are many ways and reasons to redirect your 404 pages. With this tutorial, we will redirect 404 pages to the homepage with the template_redirect hook.
Redirecting your 404 pages
add_action('template_redirect', 'themespress_redirect_404_to_homepage', 999);
function themespress_redirect_404_to_homepage(){
if(!is_404())
return;
wp_redirect(home_url());
exit;
}This function will ensure that all 404 oages will be redirected and in this case a 404.php template is not necessary in your theme.