The WordPress theme management usually takes place in the WordPress backend in the Appearance > Themes. However, in some situations, this may not be possible. For example, just after a WordPress update, or you updated your WordPress theme, your site may go all blank, and you realize that you no longer have access to the backend. In such scenarios, the only way you can try troubleshooting the issue is by using your web hosting dashboard. This is where you will have to find an alternative way to change your WordPress theme without accessing the WordPress dashboard. Even though you can install additional themes using the file manager, it won’t be possible to activate them. You will have to access the Database in order to do that, which is exactly what we are going to explain in detail.
In our previous article about disabling default WordPress themes, we have explained why is it recommended to keep the default WordPress themes on your website even though you are not using it. In such scenarios, if the default theme fails, WordPress can try activating the default WordPress theme on your WordPress installation. So, if there is no theme available, WordPress has no option but to show a blank website.
Why would someone want to change the WordPress theme from the database?
If you are not actually trying to change your theme, rather. Just want to know why someone might want to change their theme from the WordPress database, this is an explanation for you.
There could be situations where the user may not be able to log into their WordPress backend, mostly because of some hack attempts which prevent them from logging in. Or the recent theme or plugin update introduced some bugs that prevent them from accessing their WordPress backend.
Whatever the reason may be, it is completely possible to switch themes from the WordPress database itself, instead of using the user interface.
On the other hand, if you’re just lazy to log in to your backend and decided to use the database to switch themes, please do not do that. It is always recommended to use the traditional way of changing themes by navigating to Appearance > Themes from your WordPress backend.
How to Use Database to Switch WordPress Themes?
We are going to take a look at two methods you can follow to change WordPress themes using the WordPress database.
Method 1. Using phpMyAdmin
Assuming that you are using phpMyAdmin available in most of the managed WordPress hosting providers, the tutorial is going to focus on changing the theme using the phpMyAdmin database manager.
- Login to your Host and open phpMyAdmin – looking at the dashboard under Database Tools or by manually searching. If you are using a custom server, you might already know the location where phpMyAdmin is accessible.
- Locate the correct database of your WordPress website.
- Go to wp_options table (the table can have a different prefix than “wp” based on your web hosting preferences.)
- Look for the template and stylesheet in the wp_options table (usually located on the 2nd page by default.)
- Edit both of them and replace the values with the name of your theme. If you are using a child theme for the new theme, make sure to input the correct stylesheet, which will be different from the template.
- As soon as you save the changes, the theme will be changed on your WordPress website.
Method 2. Using SQL commands
If you are familiar with SQL commands and how to execute them on your WordPress website, You can use the following steps to change your WordPress theme from the SQL command line.
Step 1. Login to MySQL command line.
mysql -u username -p
It will ask you to enter the password. Provide it.
Enter password: ********
Step 2. Select the right database.
USE database_name;
Step 3. Update the template, and stylesheet values in the wp_options table.
UPDATE wp_options SET option_value = 'twentytwentyone' WHERE option_name = 'template';
UPDATE wp_options SET option_value = 'twentytwentyone' WHERE option_name = 'stylesheet';
Make sure to replace ‘twentytwentyone’ in both commands with the appropriate theme names.