Preserving theme settings in child theme

My client uses Karma theme with many settings in theme options. I need to keep my CSS and PHP additions in a child theme so that theme updates don’t wipe it out. However when I select my child theme in Appearance > Themes, the main theme settings are all gone.

Is there any way to preserve the main theme settings?


Because of the way these theme settings are stored as an array in the database, it can be difficult to copy them over with just copy and paste in phpmyadmin or some similar tactic.

The WP CLI option command is your friend here. If you don’t use WP CLI already, check it out! Here’s how I copied the settings from the storefront theme to a theme called storefront-sqcdy-child:

# save the existing theme settings in json format in a temporary text file
wp option get theme_mods_storefront --format=json > theme_mods_storefront.txt

# load the saved settings into the child theme option record in the database
wp option update theme_mods_storefront-sqcdy-child --format=json < theme_mods_storefront.txt

# cleanup the temp file
rm -f theme_mods_storefront.txt

Leave a Comment