Im struggling to get the concept of using rel=canonical
with wordpress. Ive done as much research as I could on the topic.
Backgound:
I would like to move 100 existing posts to another (new) domain BUT also keep the posts on the existing (old) domain!
I would like the posts of the new domain to appear in search results eventhough they were originally indexed on the old domain
Webmasters.stackexchange said this should not be a problem providing I use rel="canonical"
I would like to code the rel="canonical"
without making use of plugins as I understand it I need to add the code to the header.php
section of the old wordpress site.
<?php if ( is_singular() ) echo '<link rel="canonical" href="' . get_permalink() . '" />'; ?>
Numerous sources all point towards the above code having to be added to header.php
in wordpress
My Question
-
Will the above code provide a
rel="canonical"
to all existing pages and new pages in the future? -
Where in the above code do I specify which site I would like to credit with the posts (the new site)?
Sources
https://support.google.com/webmasters/answer/139066?hl=en
https://thomas.vanhoutte.be/miniblog/add-a-canonical-tag-to-wordpress-header-php/
rel="canonical"
attributes credit of current page content to the URL specified in thehref
. Made that clear, you should be using canonical link tag on the single post pages in your new site. (NOT the old site, unless you plan to take down the old site in future and keep the new site only).Answer to your first question
Technically that code will render the canonical link tag, but it will be useless in search engine perspective. Because, the function
get_permalink()
will output URL of the current post, which actually is not expected in your case. The canonical link tag in your new site should be as follows<link rel="canonical" href="http://www.youroldsite.com/respective-post-slug/"/>
Answer to your second question
In your code value of the “href” attribute should be the target link. (Instead of
get_permalink()
)I am wondering why you don’t want to use a plugin!!! This is like reinventing the wheel. “All in One SEO” and “SEO by Yoast” are from those few good plugins for enhancing SEO of your website.
Content of the posts in your old site is already crawled and indexed by search engines. Thus you should not attribute its credit to new website. I hope this clears your concept and answers your questions.