WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

i have two single woocommerce installs (not multisite) that publish the same content (products etc). i want to add a cross domain level rel canonical to the second domain, such that -

www.domain2.com/any-url/ will have a rel canonical of www.domain1.com/any-url/

it seems only way to do it is add rel canonical to every single URL manually. is there not an option to set a top level rel canonical for the whole domain?

share|improve this question

closed as off-topic by Mark Kaplun, birgire, Pieter Goosen, Johannes Pille, gmazzap Sep 28 '14 at 21:54

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Your question should be specific to WordPress. Generic PHP/JS/HTML/CSS questions might be better asked at Stack Overflow or another appropriate site of the Stack Exchange network. Third party plugins and themes are off topic." – Mark Kaplun, birgire, Pieter Goosen, Johannes Pille, gmazzap
If this question can be reworded to fit the rules in the help center, please edit the question.

What do you mean by 'manually'? If you want to have a canonical link that equals the current URL with just another domain, you can simply put that line into your header. If you want to do this (i.e., include this link) only for certain templates, you have to check if the current page is of that kind. – tfrommen Mar 7 '13 at 11:32
@t-f yes thats what i meant. what line do i need to add into the header? – user1768787 Mar 7 '13 at 11:35

Well, the basic idea is to put this line into your header.php:

<link rel="canonical" href="http://YOUR-DOMAIN.TLD<?php echo $_SERVER["REQUEST_URI"]; ?>" />

You now have to test cases (if you want to apply the link to certain pages only).

See $_SERVER for documentation.

share|improve this answer

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