Skip to main content
Code Tutorial

Disable WordPress Automatic Or Random Redirect Guessing of 404s

WordPress redirecting to random URLs and posts? Going crazy over why WordPress would do such a thing? Then maybe you find yourself asking,

"How do you to disable and stop automatic redirection of 404 errors and “incorrect” URLs to random posts and pages?"

The answer is simple, disable automatic permalink guessing for 404s.

However, the automatic WordPress redirect system is a bit more complected than meets the eye, and we need to be careful when disabling automatic redirects.

WordPress has a function called redirect_canonical(), and this function is very powerful for SEO. This function is responsible for handling any automatic redirects. If you disable the function, you can hurt your SEO. This is why it is better to prevent a sub-function of redirect_canonical(); specifically redirect_guess_404_permalink().

redirect_guess_404_permalink() is a function that looks for similar URLs registered in WordPress and will redirect old URLs to those it can find. This feature is nice to have for SEO if you are not keeping an eye on your 404 pages but can create some weird redirect behavior. That might be why you found this post interesting... you need your redirects to be more predictable.

To make your redirects more predictable disable redirect_guess_404_permalink() and not redirect_canonical(). In your theme's functions.php file add the following:

add_filter('do_redirect_guess_404_permalink', '__return_false');

Access More TypeRocket

Join our community mailing list and get notified before anyone else. Get videos and more.

By using our website you agree to our Cookie policy.