Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am moving my site from to I want to keep all of the content at but I want the canonical version in google to be recognized as instead of the same thing at

How can I modify the rel=canonical in the section of to make this change?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Unfortunately, there's no filter in the rel_canonical() function. But you can remove that function from wp_head altogether and write your own. Try adding this to the functions.php at your old domain:

remove_action( 'wp_head', 'rel_canonical' );
add_action( 'wp_head', 'new_rel_canonical' );

function new_rel_canonical() {
     if ( !is_singular() )

      global $wp_the_query;
      if ( !$id = $wp_the_query->get_queried_object_id() )

      $link = get_permalink( $id );
      $link = str_replace( '', '', $link );
      echo "<link rel='canonical' href='$link' />\n";

Obviously, just replace and in the second to last line with your actual domain names!

share|improve this answer
Something relevant: – its_me Jul 17 '12 at 16:40

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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