Incorrect Yoast canonical redirects

In the realtime view some articles don’t show the title, author, image and publication date. Instead the url of the article appears without any image.

image

When does it happen?

On Wordpress installations using Yoast in combination with a cache plugin like WPRocket, WP Super Cache or others.

Why does it happen?

When publishing from Wordpress an article to https://domain.com/path/to/new/article, Yoast initially sets the canonical as <link rel="canonical" href="https://domain.com/?p=12578" />. This short Wordpress link returns a 301 redirect to the correct url https://domain.com/path/to/new/article. This redirection is an important SEO error as explained below. When the cache is evicted some minutes after, the right canonical <link rel="canonical" href="https://domain.com/path/to/new/article" /> is added to the article.

This is a known and reported bug to Yoast.

Why a redirect in a canonical can be harmful to your SEO strategy?

Adding a 301 redirect on a canonical is documented by Google as potential source of problems

Incorrect canonical tags: Some content management systems (CMS) or CMS plugins can make incorrect use of canonicalization techniques to point to URLs on external websites. Check your content to see if this is the case. If your site is indicating an unexpected canonical URL preference, perhaps through incorrect use of rel="canonical" or a 301 redirect, fix that issue directly.

Deepcrawl also recommends and documents:

Don’t canonicalize to a target that is noindexed, or returns a non-200 status

Sitechecker recommends to fix all non-200 canonicals and to avoid redirects:

fix URLs with canonical to non-200

Sitebulb has an explicit hint check to avoid canonical redirections

The point of a canonical is to explicitly and unambiguously indicate a preferred URL. However in this situation, the canonical instructions are sending conflicting messages to the search engines - which typically means they will ignore the canonicals entirely and try to make their own decisions about what ‘the canonical URL’ should be.

Onely takes canonical redirects as site audit errors:

They will alert you of any incorrect canonicals, such as removed/missing pages (HTTP 4xx), server errors (HTTP 5xx), or redirects (HTTP 3xx) in canonical tags.

Why are other analytics tools not affected?

Marfeel creates a visual representation of a site based on the same rules Googlebot sees it. In documentation situations where Google might see an issue, Marfeel will always make it obvious and put it to the attention of our users to be able to address it the sooner the better. Marfeel is not just an analytics platform but a tool that will help you optimize your SEO strategy by following best practices and Google official recomendations.

Following this principle, Marfeel doesn’t rely on explicit and ad-hoc instrumentation provided to our pixel. Instead Marfeel exclusively relies on the Structure data of your site to infer all the information you see on the platform, the same way Google does.

This has two big benefits:

  1. Fast adoption. Site owners don’t need to spend endless hours instrumenting their site
  2. Any effort to improve the instrumentation will benefit your SEO strategy

On the other hand Marfeel always attributes the traffic of a url to its canonical. This is brings important benefits in terms of SEO and also in terms of analysis.

Solution

On the reported Yoast issue some users report non-official solutions while Yoast works on solving the issue.

Here’s an snippet of code to add on functions.php some our partners and customer have used in the past:

// Fix per canonical Yoast
function prefix_filter_canonical_replace( $canonical ) {
  if ( is_single() ) {
        $canonical = get_the_permalink();
  }
  return $canonical;
}
add_filter( 'wpseo_canonical', 'prefix_filter_canonical_replace' );
At Marfeel we are not Wordpress specialists, please use this snippet with caution after reading the reported Yoast issue and assessing how it applies to your setup.