Disable URL Guessing in WordPress

Placing the following PHP code snippet below in your theme’s funtions.php file will disable a WordPress feature that attempts to automatically redirect a bad url to an actual post or page with a similar url.

Please note, if there are any broken links to your website or it’s pages that benefit from this feature it will now lead to a standard 404 error page.

/* Disable URL guessing - */
add_filter('redirect_canonical', 'pz_no_redirect_404');

function pz_no_redirect_404($redirect_url)
    if (is_404()) {
        return false;
    return $redirect_url;

The above was found in a post at

By Joseph Dickson

Joseph Dickson is a web developer in higher education and an avid proponent of using WordPress’ core features to create flexible and manageable design solutions.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.