On making stuff with code. And making code to do stuff.

Copying theme mods to child theme using wp-cli

“Child themes” in WordPress allow for specific modifications of the look and functionality of those inherited from their “parent” theme.

Unfortunately, when you switch to the child theme, the customizations configured on the parent theme are lost, because they’re saved with the active theme slug.

So, here’s a quick and simple way to “inherit” those settings by copying those options to the child theme.

Using wp-cli:

wp option get theme_mods_PARENT-THEME --format=json | wp option add theme_mods_CHILD-THEME --format=json

… where PARENT-THEME and CHILD-THEME are the theme slugs for each theme.