Redirect all 404s to the homepage in WordPress.
Snippet Type
Execute on Child Sites
Snippet
function wp_redirect_404_to_homepage() {
if (is_404()) {
wp_redirect(home_url(), 301);
exit;
}
}
add_action('template_redirect', 'wp_redirect_404_to_homepage');
jeroenrotty
(Jeroen Rotty)
2
Just my 2 cents, it’s never a good idea to do this. See: SEO Anti-patterns: 301 redirect all your 404s to your homepage • Yoast and lots of others.
3 Likes
system
(system)
Closed
3
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.