July 12, 2008

Redirecting Blogger posts to WordPress

Filed under: Tech — Chris @ 3:48 pm

My move from Blogger to WordPress was made possible by this tutorial. However, the post redirection widget has some bugs: it doesn’t handle posts with “a”, “an”, or “the” in the title (seriously!) or titles with non-ASCII characters in them.

Here’s an upgraded widget, which works for a broader class of posts. Basically, I just translated the WordPress PHP code for generating a permalink from a title into Javascript. I cut some corners, but it’s good enough to handle 99% of the posts in my archive.

<b:widget id='Redirector' locked='true' title='Blog Posts' type='Blog'>
<b:includable id='main'>
<b:if cond='data:blog.pageType == "item"'>
<b:loop values='data:posts' var='post'>
<div id='redirectorTitle' style='visibility:hidden'><data:post.title/></div>
<script type='text/javascript'>
var new_domain = 'YOUR_BLOG_URL_HERE'

function utf8_uri_encode( str ) {
  var high_code = new RegExp(/[\u0080-\uffff]+/);;
  new_str = str;;
  while( m = high_code.exec( new_str ) ) {
    new_str = new_str.replace(m,encodeURIComponent(m));;
  return new_str;;

var title = document.getElementById('redirectorTitle').innerHTML;;
// [INCOMPLETE] Keep percent signs that aren't part of an octet?
title = title.replace(/&lt;[^&gt;]*?&gt;/g,'');; // remove tags
title = title.replace(/&amp;.+?;/g,'');; // remove entities
title = utf8_uri_encode(title);; // handle UTF-8 characters
title = title.toLowerCase();;
title = title.replace(/[^%a-z0-9 _-]/g,'');; // remove punctuation
title = title.replace(/\s+/g,'-');; // turn spaces into hyphens
title = title.replace(/-+/g, '-');; // collapse runs of hyphens
title = title.replace(/^-+/g,'');; // remove prefixed hyphens
title = title.replace(/-+$/g,'');; // remove suffixed hyphens
var timestamp = '<data:post.timestamp/>';
timestamp = timestamp.split('/');
timestamp = timestamp[2]+'/'+timestamp[0]+'/'+timestamp[1];
var new_page = new_domain + '/' + timestamp + '/' + title + '/';;
document.location.href = new_page;


  • Timestamps on posts must be in MM/DD/YYYY format. This is easily changed in the Blogger control panel via “Settings -> Formatting”.
  • You should set the correct time zone for your blog in WordPress before you import the posts. Otherwise, Blogger and WordPress won’t always agree on the date of a post. I didn’t do this and, as a consequence, about one in five of my archived posts have bad redirect links. (This can be fixed by manually editing the post’s timestamp, but that is a big pain.)
  • This mostly handles Unicode (see, e.g., this post), but there is a bug in there somewhere. I had to manually change the permalink on this post fromएक्ष्केल्लेन्त्-वर्क-टो/


    so that it redirected to the right place. (Can any Hindi readers help me out with that? Is there punctuation in there? I don’t remember what the title was supposed to say. And I can’t figure out how to back-transliterate it into English.)

  • Blogger does some weird things with the widget code after you save. The code will disappear from the “Edit Template” text box, replaced by a tag like:

    <b:widget id='Blog2' locked='true' title='Blog Posts' type='Blog'/>

    (the tag with id Blog1 is your actual posts; don’t delete it). If the widget doesn’t work, or you want to remove it, just remove that tag. If you want to fiddle with the widget, clicking “Expand Widget Templates” will reveal the underlying code (and a lot else besides). The widget will also show up in the Blogger “Layout -> Page Elements” as a mysterious second “Blog Posts” box, with all kinds of spurious configurable elements. Just ignore that.



  1. So, this has by far been the clearest explanation of all this, and the most recent… so I can trust it. There is so much bad code out there that seems to be dated to last summer I cannot believe it.

    I just have two problems.

    1) I imagine this does not transfer link juice, as it’s not a 301 redirect.

    2) On individual posts, for SEO purposes I have my individual post address as on my wordpress blog. This doesn’t translate well for your widget. What would I change in the widget to make it so it ignored blogger’s date setup in the post address? I’m having trouble explaining this to even my satisfaction, but so it does something like this:

    You can see what it does by clicking on an individual post at

    As you might imagine, it 404’s.

    Again, thanks for your recent info, it’s fantastic.

    Comment by Jimmy — July 17, 2008 @ 12:27 pm

  2. Nevermind, figured out the second question. Thanks again!

    Comment by Jimmy — July 17, 2008 @ 12:57 pm

  3. […] title. That means If you’re not, I recommend you head over to Procrastiblog as his solution takes into account the Blogger […]

    Pingback by Moving from Blogger to Wordpress - A Tale of Woe | Liberty Interactive - Search Marketing Blog — July 17, 2008 @ 3:57 pm

  4. Jimmy, I don’t think there’s any way to transfer “link juice”. Blogger won’t let you do a 301 redirect.

    Comment by Chris — July 17, 2008 @ 5:11 pm

  5. Hey, I wrote up a guide that takes into account your code (minus the timestamp) but includes all the other info as well in a nice to read format. You saved my ass.

    Anyway, here it is:
    Successfully Forwarding Blogger to WordPress

    Comment by Jimmy — July 18, 2008 @ 10:30 am

  6. @Chris
    After carefully going through your post, I have observed that…

    You are using Javascript to calculate wordpress post URLs. This will fail for search engine as they have javascript disabled. So using your way all SEO juice will be gone! 😦

    Next it puts restriction on WordPress Permalink structure. Also there may be date mismatch as mentioned by Chris. This all means your solution is not fullproof.

    Also read this official article from Google on Javascript redirects, which further makes it clear as why one should not use your codes.

    So buddy if you are newly moved better use my plugin to save your PageRank and normal traffic! 😉

    Blogger to WordPress Traffic & PageRank Redirect Plugin

    Comment by Rahul Bansal — July 20, 2008 @ 4:30 am

  7. Rahul, I agree absolutely this is not an ideal solution. But, AFAIK, this is the best-case scenario for somebody (like me) moving from Blogger to a hosted blog (and not a self-hosted blog using WordPress).

    Building up an archive on Blogger is a strategic mistake if you are terribly concerned with your PageRank and you want your blog to be a revenue-generating enterprise. In that case, you probably should do self-hosting.

    P.S. Adding <meta name="ROBOTS" content="NOINDEX, NOFOLLOW"/> (as recommended at the linked tutorial) should prevent Google from penalizing you for using JS redirects.

    Comment by Chris — July 20, 2008 @ 8:21 am

  8. I’m getting a 404 Not Found. With this URL listed:

    /running/undefined/3:01PM/undefined/race-review-drumstick-dash/ was not found on server

    It almost works!

    Comment by crossn81 — August 10, 2008 @ 2:16 pm

  9. crossn81: “/undefined/3:01PM/undefined/” means that you have the wrong timestamp format. Make sure you use MM/DD/YYYY.

    Comment by Chris — August 10, 2008 @ 2:19 pm

  10. Ooops. I changed the header format not the Timestamp. I finally got it to work, I was having trouble with the permalink structure on the WordPress side and finally found a plug-in that will work!


    Comment by crossn81 — August 10, 2008 @ 3:25 pm

  11. […] Blogger posts to WordPress « Procrastiblog: Redirecting Blogger posts to WordPress « .. « előző | következő » Hector Palacios — 2008. 08. 14. […]

    Pingback by Turulcsirip - Hector Palacios — August 14, 2008 @ 12:10 pm

  12. I’ve been searching for & playng with coding all day to get a redirect for individual posts to work – blogger to blogger vice blogger to wordpress.

    Not sure if it can be done, but I’m assuming your code should work if I could just get it inserted in the correct spot.

    Problem is, I don’t have the line:

    in my blog template.

    Any suggestions of where I should insert it?

    If I insert it within the tags, it gives me a ‘page not found’ error. However, if I remov all the coding for the individual posts redirect, the main page redirect does work, so it is something within the widget that is causing the error. Well, probably not in the widget, but where I’m placing the code in the template, since I don’t have the required line of code in mine.

    Comment by Holly — September 10, 2008 @ 2:04 pm

  13. well, I did a copy/paste, which didn’t work obviously!

    The line of code I DO NOT have in my template is:

    <b:section class=’main’ id=’main’ showaddelement=’no’

    So I’m not sure where to add the widget code.

    Thanks for any help you can provide!

    Comment by Holly — September 10, 2008 @ 2:06 pm

  14. @Holly, Are you using a custom template? The code needs to go inside whichever widget displays posts in your template. Do you have <div id=’main-wrapper’>?

    Comment by Chris — September 10, 2008 @ 2:18 pm

  15. Well bless you for replying so quickly!

    I got this widget to redirect correctly:

    But I wanted to use your’s because of the title links problem.

    I do have a custom template, and I do have several <div codes, including the one where I placed the widget in the above link, which was just following:

    <div id=wrapper

    Although the above mentioned link widget will work (for some reason yours just says the new blog address doesn’t exist), now I have a different problem!

    I have two blogs I am using to play with all of this.

    I created 5 posts in what is being tested as the ‘old’ blog which I am going to redirect from. I created comments on a couple of those posts to ensure comments will follow as well when I export/import. I used some different things for blog post titles – some with a lot of words, I included ‘the’ in the title of one, I used a ! in the title of another, I used numbers in a few others.

    I set up both blogs with the time stamp as mm/dd/yyyy format.

    I exported all the posts from the ‘old’ blog.

    I imported all the posts into the ‘new’ blog.

    However, the whole point of adding the widget is so that all (well, most) of the post links will redirect as well. Except – ARGHHHH – blogger gave each and every post a different link title in the new blog than it did in the original old blog!

    You have ANY idea what I can do about that?

    I have a blog over 3 years old with close to 500 posts, and I certainly don’t want to have to manually do the redirects!

    Many thanks again!

    Comment by Holly — September 10, 2008 @ 3:57 pm

  16. @Holly I’d need to see some examples to help further. Is the widget activating and re-writing the URL? If so, what’s an example of a URL it fails on? Specifically:

    1. What’s the Blogspot permalink for the post?
    2. What’s the WordPress permalink for the post?
    3. What is the URL generated by the widget?

    Comment by Chris — September 10, 2008 @ 4:05 pm

  17. This is the URL generated by your widget:

    If I move it under the <blogger code, it also gives an error, but a different one, just the …

    I know my first comments probably weren’t as clear as they could have been, but I am not redirecting from blogger to wordpress, but from one blogger address to another blogger address. Perhaps this is where the problem lies to begin with?

    Please note that these blogger addresses can currently only be viewed by me. If I need to have them available to you for this troubleshooting, I can change the settings for that.

    The “old” to be redirected permalink a post titled “WOO HOO!” is:

    The “new” permalink post title of the same post is:

    All else remaining the same, the old post permalinks are:
    – this-one-doesnt-have-word-test.html
    – test3.html
    – test2.html
    – test1.html

    The new post permalinks are:
    – this-one-doesn-have-word-test_07.html
    – test3_345.html
    – test2_846.html
    – test1_1267.html

    Do you see how blogger has given each one a different name than the original permalink during the export/import?

    Thanks again. I may be asking for too much to do a redirect from blogger to blogger.

    Comment by Holly — September 10, 2008 @ 4:21 pm

  18. hmm – I keep forgetting that the < things, if closed, get deleted.

    So, the correct URL that you widget gives me is:<data:post.timestamp/-/dataposttitle/

    where the dash represents the closing of the <

    Comment by Holly — September 10, 2008 @ 4:33 pm

  19. I know my first comments probably weren’t as clear as they could have been, but I am not redirecting from blogger to wordpress, but from one blogger address to another blogger address. Perhaps this is where the problem lies to begin with?

    Oh. Yes. The widget rewrites a Blogger-style link to a “WordPress imported from Blogger”-style link. It won’t work at all for Blogger-to-Blogger importing. (Sorry, I have no expertise on that.)

    Comment by Chris — September 10, 2008 @ 4:45 pm

  20. Well shoot!

    I do however, thank you very much for all your help in trying to get this to work. I’ll start back to square one I guess in my search for a blogger to blogger redirect for posts!

    Comment by Holly — September 10, 2008 @ 4:56 pm

  21. Very cool tip. I will use it.

    Comment by Thejesh GN — November 5, 2008 @ 1:17 pm

  22. Oh man. You just solved my life. What an amazing widget. Thank you so so much!

    Comment by Epiphora — January 15, 2009 @ 2:52 am

  23. hello,

    i get error related probably to this line:

    writting me about non permited type ‘Blog’ in Redirector…

    any idea?

    Comment by jirib — February 25, 2009 @ 6:22 pm

  24. jirib, It looks like your cut-and-paste got blocked. Make sure you turn > and < into &gt; and &lt; before posting.

    Comment by Chris — February 25, 2009 @ 7:00 pm

  25. Help, please! I cannot get this code to work. I try to insert it in my template after:

    And blogger will not save my template for me. It says that this widget “isn’t valid.” What am I doing wrong? It’s driving me crazy!

    Comment by Natalie — April 2, 2009 @ 4:17 pm

  26. Natalie, these instructions are up-to-date as of July 2008. I can’t guarantee they still work. The widget is still redirecting my blog, but that doesn’t mean the Blogger Template editor hasn’t changed.

    Comment by Chris — April 2, 2009 @ 8:07 pm

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Blog at

%d bloggers like this: