Auto Redirect from Blogger to WordPress

Here’s a useful bit of Javascript that will redirect your old Blogger blog account to your new, self hosted WordPress blog account once you’ve imported all your old blogs.

It uses the search function in your new account to list the possible matches (usually just the correct one!). It works this way because the blog names on blogger are rarely the same as in wordpress, but it encourages people to update their links by showing them it’s different. It also displays a helpful message.

First go to your blogger account, select “Design” tab and “Edit HTML”. To get javascript in there, you’ll need to turn on “Expand Widget Templates”, and make sure any code is properly escaped, like the example below.

Now copy this piece of code, as is (except for line numbers), just after the Body tag:

  1. <h1>Blog has moved, searching new <a href='YOURBLOG'>blog</a>...</h1>
  2. <script type='text/javascript'>
  3. var splits = location.href.split(&quot;/&quot;);
  4. var splits2 = splits[splits.length-1].split(&quot;.&quot;);
  5. var search = splits2[0].replace( /-/g, &quot;+&quot; );
  6. window.location = &quot;YOURBLOG/?s=&quot; + search;
  7. </script>

Now replace YOURBLOG with the address to your blog (e.g. )

Test it by going to one of your old Blogger blogs.

A helpful page at

22 Replies to “Auto Redirect from Blogger to WordPress”

  1. Here’s a bonus one for WordPress to WordPress auto redirection.

    Just change the old blog location to the new blog location. I’ve added a delay so anyone can see that it is redirecting and a message if the redirect doesn’t work.

    Just paste everything from the next line into your header.php file just after the body tag. Then update the OLDADDRESS and NEWADDRESS bits.

    <h1>Blog has moved, switching to new one automagically (please update you link!)…</h1>
    <script type=”text/javascript”>
    setTimeout(“alert(‘Switch over did not work. Goto: NEWADDRESS’)”,5000);
    function switchToNewBlog()
    var newLocation = location.href.replace(“OLDADDRESS”,”NEWADDRESS”);
    window.location = newLocation;

  2. Actually, this wordpress – wordpress relocation script is mich better:

    Just put these lines at the very top of your header.php file and everything will automatically be redirected. Rankings on search engines should also redirect correctly with this:

    Header( "HTTP/1.1 301 Moved Permanently" );
    Header( "Location:" . str_replace( "blog-tips", "blog", $_SERVER['REQUEST_URI'] ) );

    Use the str_replace function to switch from one website to another. e.g.: if you are moving from”” to “” use str_replace( “”, “”, $_SERVER[‘REQUEST_URI’] );

  3. Since this code will automatically redirect the blog to another, is there any code for redirecting the blog if only the homepage is open? cos from Google or Yahoo, i searched my own post (for testing), then it only show the specific html (post title) for a while before redirected to a new link. What I want is only the homepage is redirected. not the post in the blog. Help me!~

    1. Hi Nadia.

      You’ll need to check whether you are on the homepage and then redirect if you are something like:

      1. if( window.location.href == "your old blog home address" )
      2.   window.location = "your new blog address"

      Note that some home pages can have several slightly different address such as : “” and “” – you’ll need to check for each one, just or them together:

      1. if( window.location.href == "your first address" || window.location.href == "your second address" )
      2.   window.location = "your new blog address"

      Hope that helps.

  4. Thanks so much for your code! This has been the only option that has worked for me that actually links to my direct post thus saving all my Pinterest, ect. exposure and links that are currently out there! I’ve tried like 5 other tutorials that didn’t work on my site. THANK YOU! 🙂

  5. Thank you SO MUCH! Works perfect. One of my clients had a blogger, which we redesigned and migrated to WordPress a few months ago… but no matter what messages and links we put on the old one, it just keeps eating all the traffic, and of course we are being penalized by Google because of the duplicated contents. We have configured the old blogger to not get indexed by search engines. I hope that helps with the second issue. Thanks again!

  6. Hi, my old blog doesn’t seem to have a header.php in the code?
    Where do i post this? I desperately need to get this working asap.
    Many thanks.

    1. Hi Dom,

      You have to ensure the code gets added to all your blog pages. The header.php file is dependent on the template you are using, some templates may go against the recommended pattern.

      Just make sure you add the code after the tag whichever file that may be included in.

      1. Hey Matthew,

        So I’m super new to this and I was wondering if you could tell me where to post this code. Which “tag” are you talking about?

        my old blog is:

        and the new one is:

        Perhaps you could provide the exact code I need and the place to put it?

        I’ve been trying to migrate blogger to wordpress in hopes of salvaging my traffic and google cred, as my blog has become increasingly popular in the past months.

        I am heaps appreciative of this thread because it’s the closest I’ve gotten…but still so far away. Look forward to hearing back.


        1. I’m also getting an error that says:

          “Could not load template preview: Error parsing XML, line 6, column 3: The processing instruction must begin with the name of the target.”

          so I’m lost 🙁

  7. This is perfect, I’m glad I found this page from a WordPress help page.

    I moved from Blogger to WordPress approx. 3 months ago and even though I had Google stop indexing the Blogger site, I was still getting some traffic from older posts on blogs when I used my URL. Until now, I had a meta direct set but that’s not helpful as it only redirects to the homepage of the new site. This is perfect and working great, thank you.

    One question though [since you’ve obviously been there and done that], in Google Webmaster Tools it is still reporting crawl errors from the correct website but from Bloggers permalink structure. I did have Blogger on my current URL before changing to self-hosted wordpress which is why the errors are reporting the correct URLs but wrong permalinks resulting in 404 errors. For example, it’s reporting is the incorrect URL (which it is) but not redirecting to (correct URL). It shows where they’re linked from and I’ve fixed up most of the links which I can access. Is there anyway I can set a redirect so they go to the correct URL? My friend recently made the switch and her old URLs are being directed to the correct URL. How can I do the same?

    Also, in Google Webmaster Tools, I rebuilt the XML sitemap so all the correct URLs are in place and resubmitted that but the above problems are still reported. If I search my site in Google, it looks like they’ve indexed the right permalink structure. I’m at a loss what to do.

    Sorry this is so long. Hope you can help. Thanks in advance.

    1. Hi Lisa,

      Great looking site.

      I’m no expert on this area unfortunately. As far as I know, google crawlers won’t follow the javascript redirect so maybe you should also add a meta redirect which they will understand. Maybe this wordpress plugin would be useful there: redirection.

      Alternatively you could switch the Permalink Settings of your wordpress installation to match those which blogger used (i.e. with the year and month) – though that may cause errors on your current set up.

      Sorry I can’t be more help.

  8. WOW! This is a great post. I have been looking for a way to make this happen and your post has made it seem very easy. Will try it out soon. Thanks for sharing.

  9. Hi, i have followed ur instruction to redirect blogger to wordpress and it work very well. But it got redirected to my blogpost in the new website instead. I hope to redirect it to the home page actually. I saw a similar post on your forum but i think its slightly different because I’m redirecting it from blogpost to homepage, not homepage to homepage.

    my old blog is:
    my new website is:

    Please help me as I already cracking my brain over it. Thank u so much!

    1. its ok. i found the solution. Using your HTML codes, i simply removed some parts towards the end. i removed ?s=, and also removed +search;,
      i had no knowledge of HTML codes and i am damn lucky to figure it out.
      But anyways v v v much for your redirection codes! Really appreciate your good work! Cheers!

    1. I’m afraid this code wont be able to help as it only works off the URL.

      You’ll have to get the title in javascript then append that to the new search url instead of splitting the existing url.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.