Moving Sidebars with WordPress | Ed Nailor
I build a lot of websites on WordPress. And when building a new website for a client, this is typically done on a development server instead of on the live website server. This way the website can be perfected before the public sees it, and once it is ready, the website is then moved to the new server.
There are a number of websites out there telling you how to move a WordPress website from one host to another. Following a few basic steps, you can easily move the entire website with no problem. (I will review these steps in another posting soon.)
However, it seemed that from time to time when I would transfer a website, the sidebars would not transfer. This was rather baffling for a while, as this is not the expected behavior. After all, the sidebars are stored within the database, and I was moving the database… so what was the problem?
The problem lies in serialized data. To explain this better, let me review the step of editing the SQL file:
When you move the website, one of the easiest methods is to download a backup copy of the mySQL database and then edit the database for the new host. If you are changing the domain name (which I was due to dev server and live server having different domain names), you have to do a find and replace of the domain name.
The problem usually came in when I would use links within the sidebar widgets. If the dev domain name is dev.com and the live domain is livesite.com, a link within the widget would need to be changed. But since the widget data is stored serialized, I have to take an additional step to ensure this works properly.
When data is stored serialized, you will notice it looks a little different. It may read something like this:
s:126:"<div style="padding...
The 126 located here tells the database we are storing 126 characters in this area. If you do a simple find and replace using the 2 different domains (dev.com vs. livesite.com) you can see that the characters will no longer add up properly.
So in the widget section (look for entries labeled “widget_text” or other “widget” areas that you have added links and images to), before you do a general find and replace, you will need to update the character count. In the domain name example I have used, I would need to add 5 to the count to ensure the count is correct, meaning the 126 number would be changed to 131 to reflect the correct number of characters with the new domain.
Once this has been done, then you can do a general search and replace elsewhere.