How to transfer/copy WordPress theme options

The easiest is to use wp command line tool. Here we will transfer the twentytwenty WordPress theme setting to twentytwenty-child.

Install wp

curl -O
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp

Check to see if wp works:

wp --info

You would be able to see a few WordPress settings.

Export theme option

sudo -u www-data wp option get theme_mods_twentytwenty --format=json > /tmp/twentytwenty.json

We prefix the command with sudo -u www-data. Or sometimes you won’t have permission to access wp-config.php and it will give you the error like this:

PHP Warning: file_get_contents(wp-config.php): failed to open stream: Permission denied in phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php on line 603 Error: Strange wp-config.php file: wp-settings.php is not loaded directly.

Error if your current user don’t have access to wp-config.php

Import theme option

sudo -u www-data wp option update theme_mods_twentytwenty-child --format=json < /tmp/twentytwenty.json

Remove the temporary file:

rm /tmp/twentytwenty.json


By VarHowto Editor

Welcome to VarHowto!

1 reply on “How to transfer/copy WordPress theme options”

Comments are closed.