Consider the scenario where you are in wordpress:
- Install parent theme
- Customize theme via the customizer
- Run into style issue that cannot be handled via a theme option
- Create child theme to add custom CSS
- parent options are lost to the child. (Note. it’s in the database but not used or copied to the child theme. Keep in the back of your mind that options are in the database …)
Creating a child theme is not overly difficult
- create a sub-folder on the server in my case [WP_ROOT]/wp-content/themes/onepress-child
- Create two files. A functions.php file and a style.css file –> see attached for what those file look like.
- For good measure, copied the theme’s image from wp-content/themes/onepress/screenshot.png to the onepress-child directory.
- I gathered the intellegence to update the contents of the functions.php and the style.css from https://www.smashingmagazine.com/2016/01/create-customize-wordpress-child-theme/ and https://lorepirri.com/onepress-wp-theme-change-copyright.html
Thanks – these were well written
Now I had a valid child theme, I thought I was through. When I activated the child theme all the customizations that I spent hours implementing were lost. Although that pesky footer was now correct.
- I found this reference which got me one step closer .. https://www.sktthemes.net/forums/topic/theme-options-lost-when-creating-a-child-theme/ . The options are stored in the database (remember..) so I ran a select on the wordpress options table..
- select * from wp_options where option_name like ‘theme_%’
- I found two rows. One had a option_name of theme_mods_onepress and the other theme_mods_onepress-child. It occurred to me that all I had to do was copy the option_value in the parent to the child row.
- I used the following SQL
UPDATE `wp_options` t1, `wp_options` t2 SET t2.option_value = t1.option_value WHERE t1.option_id = 150 AND t2.option_id = 330; commit;
The 150 is the id of the row that contains the values I want to copy – the 330 is the id of the row I want to copy to..
Well that’s all it took..
Hope his helps someone else face with a similar issue.