I want to set the set the cannonical url programmatically for every post.

By that I mean when creating/editing an article there should be the possibility to set a custom cannonical url for it. (maybe via custom fields?).

Right now I am using the WP Seo by Yoast as Seo plugin.

Best regards

  • under the title, you have the permalink which is editable
    – mmm
    Commented Aug 6, 2015 at 16:54
  • Well, I don't want to change the permalink. Of the article. Lets assume something like this: stackoverflow.com/questions/4530708/… this is why i want to be able to set the cannonical manually for everypost
    – Salexes
    Commented Aug 6, 2015 at 17:39
  • if I understand, you want that different URL show the same post ? where do you want use these different URL ?
    – mmm
    Commented Aug 6, 2015 at 17:42
  • Exactly. I want it exactly like in the link i posted in my other comment "I would like to use (1) as the canonical URL for OpenGraph/Facebook, so if you "like" (2) and (3) then will count for (1).
    – Salexes
    Commented Aug 6, 2015 at 18:34

1 Answer 1


You can do that programmatically right from inside the plugin's settings by using the wpseo_canonical filter.

You can also set it on a per post basis:

Yoast Canonical links settings

You can even set the canonical links for categories, tags and any taxonomy for that matter as well. All you have to do is follow instructions at Canonical URLs in Yoast SEO

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.