Hi again ??
Filters allow attaching of functions. In such a function, you can set conditions.
This is what you’re looking for, although I don’t recommend using it for all the aforementioned reasons:
add_filter( 'the_seo_framework_rel_canonical_output', function( $canonical_url ) {
$tsf = the_seo_framework();
$robots = $tsf->robots_meta();
if (
isset( $robots['noindex'] ) && $robots['noindex'] === 'noindex' // noindex is set.
&& $tsf->get_current_canonical_url() === $tsf->get_current_permalink() // The canonical URL points to the current page.
) return '';
return $canonical_url;
} );
I found that Google generally takes anywhere from a few minutes to half a year (depending on how popular the content is) to not only find but to utilize the updated meta tags thereafter. The latter is of most importance here.
Now, I believe it’s more of an issue for Google to solve, rather than for us. In any case, time will fix this issue automatically.
I think omitting the canonical URL will force Google to question its cache, and therefore they’ll reparse your page directly. Thanks for this valuable insight ??
So, I’ve escalated this issue on GitHub:
https://github.com/sybrew/the-seo-framework/issues/370