Change your theme and lost your custom CSS changes? Here’s a way to recover it.
Lately I’ve been going through to update the main theme being used around ourwebgrove.com. One thing lead to another and I managed to misplace the primary theme’s additional CSS edits and I had already deleted the parent theme that the child theme had been relying on.
If you find yourself in a similar situation and was hoping to pull that useful data back without having to revert to a previous backup hopefully this works for you.
- Custom CSS changes made using the style editor are saved in the WordPress database
- Easiest way to access the information is to interface with mysql over ssh.
$> mysql <yourhostname> -u <username> -p
- If you forgot the info used for the wordpress setup you can also find it under in your wordpress’s wp-config.php file under the main folder.
- Once you are logged in check what databases are available:
mysql> show databases;
- Load your wordpress’s database:
mysql> use <yourwordpressDBname>;
- Since I had made changed the default DB scheme I needed to check the list of available tables:
mysql> show tables;
- What you are looking for is the table most likely ending with “posts”.
- If your WordPress site is setup as a multi-site then you’re going to have to multiple tables ending in “posts”. You’ll have to run the next step altering the table name for each variation.
- Insert the table name you are needing to check into the following syntax: SELECT * FROM <your-table-posts> WHERE post_type = ‘custom_css’/G
- That /G at the end super useful since it tells mysql to format the returning query vertically. Now it’ll be easier to parse the relevant custom css edits.
- From here you can just copy the data into your favorite CSS editor and remove any left over SQL syntax leaving only the CSS entries.