Prevent YOAST from overwriting Canonical Tag

Posted in: Newsmag
Post count: 217

Hi,

YOAST SEO is overwriting the canonical tag of the theme. That’s an issue, because Yoast injects the wrong canonical tag on my paginated front page.

On Page 2 it says http://www.domain.com/ instead of http://www.domain.com/page/2/. If I deactivate Yoast it’s all good and it shows the correct canonical.

Thank you for your help!

Post count: 217

I tried “add_filter(‘wpseo_canonical’, ‘__return_false’);”, but that removes the canonical tags completely.

Post count: 6535

Hi

I’ve made some tests on my side with default settings from Yoast plugin and pagination works fine. Try to test the site using plugin’s default settings, clear all caches and check how it goes.
Thanks!

Post count: 217

Hi,

the pagination on my static front page works fine, only the canonical tag is the problem.

Please take a look: http://dev.promicabana.de/wordpress/page/3/

In the source cods you see: <link rel=”canonical” href=”http://dev.promicabana.de/wordpress/&#8221; /> instead of <link rel=”canonical” href=”http://dev.promicabana.de/wordpress/page/3/&#8221; />

I deactivated all plugins, deleted all browser caches – the problem persists. I even installed a fresh copy of the Yoast Seo plugin. It’s always the same: With YOAST – the canonical tag is false; without Yoast – the canonical tags are correct.

Thank you!

Post count: 6535

HI

It seems that this is the default functionality of Yoast plugin in this regard but you can add a condition n page’s head and change it. Add bellow code in header.php like here: http://screencast.com/t/MVJqXC65t

    global $paged;
    if ($paged > 2) {
        echo '<link rel="canonical" href="http://localhost/newsmag/' . $paged .'/">';
    }

Thanks!

Post count: 217

Hi Andrei,

thanks for the solution. I tried it, but nothing happens. It seems that yoast still overwrites every rule. 🙁

Post count: 217

Hi,

I noticed, that your solution only works on categorys. But in this case it’s the wrong canonical (yoast does it right on catgeorys) and I got two canonicals there.

Please take a look: dev.promicabana.de/wordpress/homepage-fashion/page/3/

Maybe you know a solution to disalbe the Yoast canonical tag, but only for the paged frontpage-pages?

Thank you!

Post count: 6600

Hi,

It seems that Yoast is not aware of the posts pagination used on theme’s latest articles section. You could try to filter the canonical element and not return it for your homepage using wp’s conditionals.

https://kb.yoast.com/kb/canonical-urls-in-wordpress-seo/
https://codex.wordpress.org/Conditional_Tags

If you can’t manage this on your own we recommend you ask help from a freelancer.

Thank you!
Lucian C. tagDiv

Viewing 8 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic.