WordPress – How to copy or duplicate all theme options from parent theme to child theme

Consider the scenario where you are in wordpress:

  1. Install parent theme
  2. Customize theme via the customizer
  3. Run into style issue that cannot be handled via a theme option
  4. Create child theme to add custom CSS
  5. 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 …)

I was using the onePress WordPress theme.  It was working great until I needed to change the very bottom footer text. The onePress Theme  has a recommend way to override which involves a child theme.

Creating a child theme is not overly difficult

  1. create a sub-folder on the server in my case [WP_ROOT]/wp-content/themes/onepress-child
  2. Create two files. A functions.php file and a style.css file –> see attached for what those file look like.
  3. For good measure, copied the theme’s image from wp-content/themes/onepress/screenshot.png to the onepress-child directory.
  4. 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.

  1. 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..
  2. select * from wp_options where option_name like ‘theme_%’
  3. 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.
  4. 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.

Leave a Reply