title: Setting Rel="Canonical" on each wordpress post
body: <p>Im struggling to get the concept of using <code>rel=canonical</code> with wordpress. Ive done as much research as I could on the topic.</p>
  
  <p><strong>Backgound:</strong></p>
  
  <p>I would like to move 100 existing posts to another (new) domain BUT also keep the posts on the existing (old) domain! </p>
  
  <p>I would like the posts of the new domain to appear in search results eventhough they were originally indexed on the old domain</p>
  
  <p><a href="https://webmasters.stackexchange.com/questions/92030/moving-content-from-one-site-to-another-keep-content-on-both-sites?noredirect=1#comment113982_92030">Webmasters.stackexchange</a> said this should not be a problem providing I use <code>rel="canonical"</code></p>
  
  <p>I would like to code the <code>rel="canonical"</code> without making use of plugins as I understand it I need to add the code to the <code>header.php</code> section of the old wordpress site.</p>
  
  <pre><code>&lt;?php if ( is_singular() ) echo '&lt;link rel="canonical" href="' . get_permalink() . '" /&gt;'; ?&gt;
  </code></pre>
  
  <p>Numerous sources all point towards the above code having to be added to <code>header.php</code> in wordpress</p>
  
  <p><strong>My Question</strong></p>
  
  <ol>
  <li><p><strong>Will the above code provide a <code>rel="canonical"</code> to all existing pages and new pages in the future?</strong></p></li>
  <li><p>Where in the above code do I specify which site I would like to credit with the posts (the new site)?</p></li>
  </ol>
  
  <p>Sources</p>
  
  <p><a href="https://support.google.com/webmasters/answer/139066?hl=en" rel="nofollow noreferrer">https://support.google.com/webmasters/answer/139066?hl=en</a></p>
  
  <p><a href="https://thomas.vanhoutte.be/miniblog/add-a-canonical-tag-to-wordpress-header-php/" rel="nofollow noreferrer">https://thomas.vanhoutte.be/miniblog/add-a-canonical-tag-to-wordpress-header-php/</a></p>