For those who’ve been a longtime reader of Martech Zone, you’ve most likely seen that there’s a ton of progress on cleansing up the positioning… particularly unhealthy inside hyperlinks, tons of redirects, elimination of articles to discontinued platforms, and updating of crucial articles. Working nights and weekends, I’ve most likely deleted over 1,000 articles after which edited over 1,000 extra… and my work isn’t performed.
One other practical change that I’ve made to the positioning is incorporating referral hyperlinks to third-party platforms. For those who click on on a latest article, you’ll see that the hyperlink begins with https://martech.zone/refer/ after which brings you to the third social gathering. That’s permitting me to do a few issues:
- Monitor all of my referrals to different firms in order that they’ll see the worth of sponsorship or present a referral hyperlink from my web site.
- Reducing again on the variety of backlinks requests from lazy web optimization professionals as a result of they need to use my web site as a backlink supply relatively than present worth to my readers. My robots.txt file is up to date to dam the refer path from crawling.
One subject that I’m working into with the variety of articles and inside redirects that I’ve on my web site is that WordPress’ default function the place it guesses a redirect is wreaking havoc. Core to that is that the redirect guess function doesn’t embody my redirects that are printed with Rank Math… but it surely’s usually overwriting them with irrelevant inside articles. I’m unsure if it’s a bug with their logic or simply an oversight, but it surely’s not optimum. Even worse is that if WordPress is offering these as 301 redirects to go looking engine crawlers.
How To Disable Redirect Guess Performance With WordPress
WordPress does supply the power to take away this function altogether, but it surely’s not a visual choice in your WordPress settings. As an alternative, you’ll should customise your theme file by including the next filter to capabilities.php:
add_filter( 'do_redirect_guess_404_permalink', '__return_false' );
I don’t need to dismiss the significance of this performance. In case you have a consumer who’s making an attempt to get to a web page in your web site and it ends in a 404 web page, that’s not an optimum expertise. Redirecting them with a related web page as a substitute is implausible. It’s simply that there are limitations the place it’s not optimum.
What I’ve seen is that I’ve a referral hyperlink in an article… despite the fact that it’s not a 404, WordPress guesses that it’s as a result of there’s no precise web page. So my readers get caught in a loop that by no means takes them to the vacation spot web page. It’s fairly irritating… so I need to ensure that WordPress by no means guesses a redirect for paths which can be obtainable by way of redirects.
How To Disable Redirect Guesses With Particular Paths With WordPress
Consequently, I wrote a selected perform for my theme that ensures that WordPress by no means guesses relating to some paths:
add_filter("do_redirect_guess_404_permalink", "modify_do_redirect_guess_404_permalink_defaults", 10, 1);
perform modify_do_redirect_guess_404_permalink_defaults($do_redirect_guess) {
// Get the requested URL
$requested_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
// Examine if the requested URL begins with the particular paths
$specific_paths = array('https://martech.zone/refer/', 'https://martech.zone/acronym/');
foreach ($specific_paths as $specific_path) {
if (substr($requested_url, 0, strlen($specific_path)) === $specific_path) {
// Disable 404 guessing for the particular paths
$do_redirect_guess = false;
break;
}
}
// Return the modified $do_redirect_guess variable
return $do_redirect_guess;
}
This might be written, after all, for particular pages, posts, classes, or every other use case the place you don’t need WordPress to guess the vacation spot web page once they can’t discover a particular URL.
Disclosure: Martech Zone is utilizing affiliate hyperlinks on this article.