admin管理员组文章数量:1122832
This client is using Yoast SEO (the free version) to specify primary categories for posts, a feature not available in the WordPress core. They discovered recently, via an SEO report, that the same post can be accessed multiple ways by changing the category slug in the URL. The WordPress permalink settings are set to a custom structure, as follows: /company/news-views/%category%/%postname%/
So, while the canonical URL of a post might be /company/news-views/sustainability/blah-blah-blah/
, where sustainability
is the primary category, you can also access the same post via /company/news-views/aircraft-management/blah-blah-blah/
, where aircraft-management
is another category that has been set on the post. I've checked the source HTML of both URLs and both have the same canonical URL meta tag. That is, the HTML looks something like:
<link rel="canonical" href="/" class="yoast-seo-meta-tag" />
My question is, how can we force an automatic redirect to the canonical URL if a non-canonical URL is entered? One would think that Yoast would have this feature. (Maybe it's only available in the premium version?) I'm aware of the redirect_canonical
filter, but I'm not sure how to obtain the canonical URL by using that filter, especially since the filter does not supply a $post
or $post_id
parameter. The redirect_canonical
function fires before the global $post
variable is set. Or perhaps I need to override a different filter/action, like maybe pre_get_posts
?
This client is using Yoast SEO (the free version) to specify primary categories for posts, a feature not available in the WordPress core. They discovered recently, via an SEO report, that the same post can be accessed multiple ways by changing the category slug in the URL. The WordPress permalink settings are set to a custom structure, as follows: /company/news-views/%category%/%postname%/
So, while the canonical URL of a post might be /company/news-views/sustainability/blah-blah-blah/
, where sustainability
is the primary category, you can also access the same post via /company/news-views/aircraft-management/blah-blah-blah/
, where aircraft-management
is another category that has been set on the post. I've checked the source HTML of both URLs and both have the same canonical URL meta tag. That is, the HTML looks something like:
<link rel="canonical" href="https://www.example.com/company/news-views/sustainability/blah-blah-blah/" class="yoast-seo-meta-tag" />
My question is, how can we force an automatic redirect to the canonical URL if a non-canonical URL is entered? One would think that Yoast would have this feature. (Maybe it's only available in the premium version?) I'm aware of the redirect_canonical
filter, but I'm not sure how to obtain the canonical URL by using that filter, especially since the filter does not supply a $post
or $post_id
parameter. The redirect_canonical
function fires before the global $post
variable is set. Or perhaps I need to override a different filter/action, like maybe pre_get_posts
?
1 Answer
Reset to default 0I had the exact same problem, and I believe that was probably caused because Wordpress doesn't know about the primary category (that is something added by Yoast SEO instead).
So is something that in my opinion Yoast SEO should manage, hopefully in next releases they'll do it.
In the meanwhile it looks I've smoothly resolved adding even Permalink Manager (free version is ok) plugin.
It solves both these two problems
- It adds redirects to canonical even when the permalink includes the category
- It makes internal post and pages links point correctly to the path composed by the primary category
Could even be even just random, and maybe just a cache issue that installing Permalink Manager solved, but I've tried to deactivate it and I had again the same issue. So it looks that that plugin is the solution.
Please let me know if it solves the problem even in your case.
本文标签: How can I do automatic redirects to canonical URLs as defined by Yoast SEO
版权声明:本文标题:How can I do automatic redirects to canonical URLs as defined by Yoast SEO? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736309894a1934184.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论