Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

put on hold as off-topic by Mark Kaplun, birgire, Pieter Goosen, Johannes Pille, G. M. 2 days ago

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, G. M.
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. –  t f 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

1 Answer 1

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.