Moving from Blogger to WordPress
September 14, 2009 Leave a comment
Over the weekend I migrated from Blogger (hosted by Google) to WordPress (hosted by me). Overall, WordPress feels far superior, but the migration was not without problems. Here’s a short guide to what I had to do:
First, grab the latest version of WordPress. Being a PHP application, it just drops into a directory and works 🙂
Create a database, set config
WordPress has a setup script but being a bit of a noob I couldn’t give it write permission to my filesystem. If you are also afflicted by such inadequacies the following steps may help you. For clarity I’ll call my DB ‘wordpress’. First, set up your database:
- mysql -u root
- CREATE DATABASE wordpress;
- GRANT ALL on wordpress.* TO ‘wordpress’@’localhost’ identified by ‘wordpress’;
You’ll need a wp-config.php file – WordPress comes with a default one which you can copy thusly (in the root directory of your wordpress directory):
cp wp-config-sample.php wp-config.php
Now edit wp-config.php, and fill in the details to make it look a little like this:
// ** MySQL settings – You can get this info from your web host ** //
/** The name of the database for WordPress */
/** MySQL database username */
/** MySQL database password */
/** MySQL hostname */
Hitting the site now should show a default WordPress installation with some dummy content. Whoop.
Import from Blogger
Importing from Blogger is pleasingly simple – just use the Tools -> Import option on the menu. It’ll ask you to verify access and then pull down all your posts and comments.
It’s not perfect though – for me the post Tags were imported as Categories. To get them to be Tags again, go to the Posts -> Categories menu and use the handy Categories to Tags converter.
I found that the imported Post markup was pretty mangled (I think this is Blogger’s fault, not WordPress’) – <br />s everywhere and no line breaks. To resolve this I cracked open mysql again and ran the following:
- use wordpress;
- UPDATE wp_posts SET post_content = REPLACE(post_content, “<br />”, “n”);
That sorted me out alright. Next we need to set up how our permalinks work. Set this in the Settings -> Permalinks menu, and use the following format to mimic the Blogger urls:
WordPress will either write a .htaccess file for you at this point, or tell you it can’t write to the filesystem and give you a short text config which you must manually copy into a file called .htaccess.
One final thing to note is that WordPress constructs its slug urls differently to Blogger (WordPress would use ‘the-trouble-with-new’ vs Blogger’s ‘trouble-with-new’, for example). If you’re importing blog posts this means your urls won’t always match, so any incoming links will be broken. I couldn’t find an easier way to correct them than just copy/paste by hand – doesn’t take long though.
This whole step is entirely optional.
Because I’m a geek I post code fairly often. I used the SyntaxHighlighter library back in the Blogger days and wanted to keep using it. You can install the WordPress plugin version from http://www.viper007bond.com/wordpress-plugins/syntaxhighlighter/. The old syntax didn’t seem to work, so I needed to go back into mysql and run the following:
UPDATE wp_posts SET post_content = REPLACE(post_content, "<pre name="code" class="js">", "[c0de language="js"]"); UPDATE wp_posts SET post_content = REPLACE(post_content, "</pre>", "[/c0de]");
NOTE: So that WordPress doesn’t interpret those tags above I’ve changed the ‘o’ in code to a ‘0’. You need to change it back 🙂
This just swaps all your old <pre name="code" class="js"> and </pre> tags for [c0de language=”js”]and [/c0de] respectively. Repeat the first line for any other languages you have used (for me this was xml, css, html and ruby).
WordPress doesn’t like the world to see your content via RSS. Odd, isn’t it? There’s an option in Settings -> Reading which claims to output the full text of each article into your feed, but it doesn’t seem to work. Instead, what you need to do is hack your theme a little. You’ll need to edit the wp-includes/feed-rss2.php file and change line 47 from <?php the_excerpt_rss() ?> to <?php the_content() ?>.
If you’re using Feedburner or similar, don’t forget to give it your new feed url too. In this case you should also update wp-content/themes/yourTheme/header.php and swap out the occurrences with your Feedburner url.
Upload and update DNS
At this point everything should be working nicely, so upload your blog folder and update your DNS settings. I’m guessing if you’re hosting WordPress yourself you don’t need help with this. I’ve made my own blog into a git repository up on Github, allowing me to deploy any changes I make using Capistrano. It’s a nice solution – for more information see this lovely post by the gentlemen at imedo.