Migrating a WordPress Website

Written by Jeremy LaDuke

I wrote this article for another site a while ago. It is intended for web designers who are having trouble moving a WordPress website installation from one URL to another. If you have any questions please ask them in the comments 🙂

For the most part, whenever I build out a WordPress website theme I will start with a blank slate and customize it for the client.

Occasionally though I will use a ready-made theme and customize it heavily for the client. These themes often have options that are easier to set in the theme rather than hard-coding them into the theme files. With these themes, everything is great until I go to take it from a temporary URL to the live website URL.

90% of everything transfers over flawlessly. But, sometimes revert to default. This usually isn’t a very difficult fix because it simply involves changing 2 to 3 options back to what I  had set.

Recently though I used a theme that had several options that were easier to use rather than hard-coding.

When I launched the site I went into a panic because it looked like only 40% of the dev site had made the transfer.   60% of the content and some of the layout had vanished.  this motivated me to finally figure out what was going on with the theme migrations.

The problem stems from the fact that these themes use the WordPress API to store their option values in the database.

They get stored in this format:

type:string:value

So when I went from oldurl.com to newwebsiteurl.com what I would usually do is search and replace any occurence of ‘oldurl.com’ with ‘newwebsiteurl.com’.

However, in the database, it looks like this because the WordPress API stores the values with serialization:

"header_image":s:27:"http://oldurl.com/image.jpg" changes to
"header_image":s:27:"http://newwebsiteurl.com/image.jpg"

Looks good, right?  That’s what I thought too, but unfortunately, if the value of the string is not the same length as the value of the option then WordPress resets it to its theme default.  Instead of the revised URL being

"header_image":s:27:"http://newwebsiteurl.com/image.jpg" 

it should be
"header_image":s:32:"http://newwebsiteurl.com/image.jpg".

Notice how the number after the ‘s:’ changes. That is the number of characters in the string that follows it.  If that number doesn’t match the actual number of characters in the following string then it becomes null and void.  Now theoretically you could go in the database and manually edit the string values, but trust me… it’s not worth it. Luckily there are a couple of great tips out there that I wanted to pass along so you don’t have to risk pulling your hair out!

  • Pixel Entity – has created an amazing tool that has been a timesaver for me on several projects.  You simply upload your sql file and it does all the work!
  • Moving WordPress – WordPress codex explanation of theme migrations and some basic good-to-know nuggets.
  • WordPress Move – what looks to be an impressive plugin that could help jump through some of these hoops.

Leave a Reply