If you make changes to the appearance of the theme on your WordPress site and then find that you can’t edit what you need using the built-in tools, it may be time to swap to a child theme.

A child theme allows you to modify as little or as much as you need, without affecting the parent (original) theme and also makes updating the theme easier.

However, if you go ahead and create a child theme after you’ve already customised the appearance of the parent theme, you’ll find that all your customisations are lost.

It’s possible to copy those customisations from the parent theme to the child theme using a couple of SQL queries.

First, ensure you’ve created and activated the child theme. You’ll see that your customisations are missing.

Next, deactivate the child theme and activate any other theme before continuing.

SSH to your web server, then connect to mysql and run this query to copy the customisations into a temporary variable. This needs to be done because you can’t do everything in a single MySQL query which inserts values using a SELECT statement which refers to the same table. See https://dev.mysql.com/doc/refman/8.0/en/insert-select.html

Note that you’ll need to use your own database prefix for the table names (e.g. change wp_options to myprefix_options) if you’ve set up WordPress like that.

mysql> select option_value INTO @TempValues from wp_options where option_name ='theme_mods_yourthemename';

Query OK, 1 row affected (0.03 sec)

Check the value stored in the variable:

select @TempValues;

…

| a:7:{i:0;b:0;s:18:"nav_menu_locations";a:1:{s:7:"primary";i:11;}s:18:"custom_css_post_id";i:8;s:12:"accent_color";s:7:"#1368b2";s:12:"header_image";s:73:"https://www.example.co.uk/wp-content/uploads/2017/01/header.jpg";s:17:"header_image_data";O:8:"stdClass":5:{s:13:"attachment_id";i:10;s:3:"url";s:73:"https://www.example.co.uk/wp-content/uploads/2017/01/header.jpg";s:13:"thumbnail_url";s:73:"https://www.example.co.uk/wp-content/uploads/2017/01/header.jpg";s:6:"height";i:426;s:5:"width";i:1280;}s:16:"sidebars_widgets";a:2:{s:4:"time";i:1562634638;s:4:"data";a:5:{s:19:"wp_inactive_widgets";a:0:{}s:8:"footer-a";a:1:{i:0;s:13:"custom_html-2";}s:8:"footer-b";a:0:{}s:8:"footer-c";a:0:{}s:7:"sidebar";a:8:{i:0;s:8:"search-2";i:1;s:14:"recent-posts-2";i:2;s:12:"categories-2";i:3;s:11:"tag_cloud-3";i:4;s:13:"media_image-2";i:5;s:13:"media_image-3";i:6;s:6:"text-3";i:7;s:13:"media_image-4";}}}} |

…

1 row in set (0.00 sec)

Apply the customisations to the child theme

mysql> update wp_options
    -> set option_value = @TempValues
    -> where option_name = 'theme_mods_yourthemename-child';

Query OK, 1 row affected (0.00 sec)

Rows matched: 1  Changed: 1  Warnings: 0

Activate the child theme again and you’ll now see the customisations are visible in the child theme.