0
votes

I am creating a WordPress child theme for an existing website where the original developer was not particularly experienced with WordPress and has edited code within the original theme and plugins. I'm slowly going through the process of decoupling the code edits from the parent theme into the child theme.

I have copied across the row in wp_options where option_name is theme_mods_{parentthemename} to theme_mods_{childthemename} and this is usually enough to transfer across the main theme settings.

However, the site uses 21 sidebars with 46 active widgets and has a further 85 inactive widgets. When switching to the child theme, which has an identical sidebar setup (to outward appearences), 53 widgets are placed in the sidebars in what looks like a random order. The sidebars do not even contain the same amount of widgets.

There was no previous theme with the child theme name.

Is there any particular reason why these widgets are getting in a mess? Are there any further options within the database that I need to transfer or is this something I will just need to update manually?

Many thanks for any thoughts

1

1 Answers

1
votes

Moving CSS and HTML from a modified parent theme into a child theme is a standard thing to do when creating a child theme. Trying to move database options from a parent theme to a child theme is an unusual thing to have to do, and it will get messy because of the options data in the database.

Themes store some site and theme options - like color and header images, and widget settings - within serialized data in the database, and directly editing options in the options table with phpmyadmin will break these options because the edited string lengths are different, i.e. the name of the parent theme's string length is different than the child themes'. Unless you unserialize and then reserialize the data; but editing in phpmyadmin won't account for this.

There's nothing you can do about the serialization issue unless you change the way the parent theme saves these options in the database. WordPress themes available in the wordpress.org theme directory have been checked for standard coding practices, such as saving options; some private themes don't follow these guidelines.

But once you have the child theme created and the widgets reset, the options will remain in the database, even if you change to another theme and then change back to that child theme.

You can try a tool like interconnectit.com WordPress Serialized PHP Search Replace Tool that correctly deserializes/reserializes data in the database by string. I don't know if it will work, but I've used it many times to move a WordPress site from one domain to another by finding/replacing the domain, which can occur in theme options and widget data. Once again, it depends on how the options data is saved in the database by your theme.