Preserving theme settings in child theme

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