WordPress allows you to easily change the active theme through the admin dashboard. Unfortunately, the admin dashboard can become inaccessible after you activate a new theme or update your active theme.
How do you change the active theme in WordPress without using the admin dashboard?
This will be the focus of this post. We will discuss different methods you can use to change your active WordPress theme directly through the WordPress database.
Table of contents
Reason for changing theme from the database
The primary reason to change your website’s theme from the database is that the WordPress admin dashboard is inaccessible. This can happen for a variety of reasons, including but not limited to corrupt core files, server misconfiguration, or problems with the WordPress .htaccess file.
If the admin dashboard becomes inaccessible right after you update or change the active theme, you can usually get your website up and running again by changing the currently active theme. It is generally a good idea to have a default theme installed on your website so that you can activate it whenever the need arises.
Before we cover how to change the active theme from the database, let’s discuss different factors that can make the WordPress admin dashboard inaccessible after you activate or update a theme. This can help diagnose the issue so you can go back to using your preferred WordPress theme.
How can activating or updating a theme make the WordPress admin dashboard inaccessible?
Since WordPress is open-source, its code is available for everyone to download and customize. A big community of developers has also built around WordPress. These developers have created many plugins and themes that you can use on your WordPress site.
The ability to completely customize the code and availability of so many themes and plugins means there are a lot of unique configurations in which people can set up their WordPress installation.
Responsible WordPress theme developers test their theme in a variety of environments. However, it is impractical to test a theme in every possible configuration and setup. This makes it difficult to determine if any of them could lead to breaking changes and, for example, make the dashboard inaccessible.
Some reasons that could make the admin dashboard inaccessible when you install or activate a theme include:
Plugin incompatibility
Different website administrators are likely to install a different set of plugins depending on their needs. This is completely fine most of the time.
However, there are some instances when a website malfunctions or becomes inaccessible because of a conflict between different plugins and/or themes. This is known as plugin incompatibility. There are many possible reasons for plugin incompatibility, including:
- The installed plugins are not up-to-date: An outdated plugin might be making an API call or calling a function that no longer exists. This could throw errors, making the admin dashboard inaccessible.
- The theme relies on other plugins to offer additional related functionality: The theme might throw errors if it can’t find all those plugins.
- A third-party plugin can have code that conflicts with a particular theme: Installing the plugin on a website where that particular theme is active could create problems. It is always a good idea to check if there is any reported incompatibility between the installed plugins and the active theme on a website.
Server configuration mismatch
Another potential cause of errors when you activate/update a theme is the server configuration not matching the theme’s requirements.
These requirements can be related to the installed PHP version, memory limits, execution time limits, or file upload limits, among other things.
Usually, you will be able to find out and update these values yourself using your web host’s control panel. For instance, cPanel has a Select PHP Version menu option under the Software section where you can change the current PHP version, maximum execution time, memory limits, file upload limits, and installed extensions.
If you have trouble figuring out how to make the server configuration match the theme’s requirements, then this is something your web host’s support staff can help you out with.
Improperly coded theme
Theme developers might not always test their themes thoroughly. If this is the case, it is more likely to throw errors.
Often, it’s best to switch to another theme if this is the cause.
However, there are a few other things you can try to resolve these errors:
- You could get in touch with the theme’s support team. If other WordPress administrators are also reporting issues with a particular theme, it is more likely to be the source of error instead of some other underlying cause.
- You could also modify the theme code yourself to fix the error. We don’t recommend this unless absolutely necessary.
Incorrect custom code
Sometimes, WordPress administrators or programmers they hire make changes to a theme’s code. They do this to either add new functionality or make changes to the standard theme.
This custom code could have errors and ultimately result in an inaccessible WordPress admin dashboard.
Methods for changing theme from the database
WordPress uses database tables to store a website’s configuration options and content. There are different dedicated tables to store different types of data.
WordPress uses the wp_options table to store various configuration settings and options related to your site. This includes information about the currently active theme on your site. Changing this information in the database will change your site’s active theme.
Please keep in mind that the table prefix isn’t always going to be wp_. Its exact value depends on what was entered during the installation process.
There are three methods that you can use to change your WordPress site’s theme through the database.
Please keep in mind that directly changing the database contents can prevent your website from functioning if not done correctly.
It is a good idea to always create a backup of your database before you proceed to change it. This will help you easily restore everything back to its previous state.
Change the WordPress theme through the database in phpMyAdmin
There is a good chance the control panel your web host provides for managing your website comes with phpMyAdmin preinstalled. This database administration tool is a beginner-friendly option for anyone who wants to view or modify database content.
If your host uses cPanel, you can find the link to open the phpMyAdmin tool in the Databases section, as shown below.
Select the website database
Clicking on phpMyAdmin will take you to the next page where you will see a list of databases in the left sidebar. You might find one or more databases in the list depending on the number of installed websites.
Click on the name of the website’s database in the left sidebar.
There is no need to worry if you can’t figure out the right database name. The WordPress wp-config.php file also contains this information. You can find this file in the root directory of your WordPress installation.
Simply open the file in a text editor such as Notepad and look for a line similar to the one below:
define( 'DB_NAME', 'YOUR_DATABASE_NAME' );
Here, the text in place of YOUR_DATABASE_NAME is the database that WordPress uses to store your site’s information.
Find this database name in the sidebar of phpMyAdmin and click on it. This will open a list of tables in the database on the right side.
Select the options table
Look for a table with the name PREFIX_options. As we explained in the previous section, the exact value of PREFIX is set during the installation process. However, all the tables will have the same prefix making it easy to figure out.
In the image below, you can see that the prefix value is mJbd. Your tables will have a different prefix.
Click on the options table. This will display a list of rows that store different configuration settings and options for your WordPress site.
You will notice that the table contains many rows. We will use the Filter rows option to find the row with options that we want to edit. However, the Filter rows option only searches rows visible on the page.
We can load all rows at once by checking the Show all box highlighted in the image below.
You should be careful when loading all rows as it can create performance issues and possibly crash the browser.
If that happens, you should try loading 500 rows at once by selecting 500 from the Number of rows dropdown.
Update the option values
There are two options whose value we need to update to change the active theme. The option names are stylesheet and template.
Enter the term stylesheet in the Filter rows input field. This will display the stylesheet row.
When we do that for our site, you can see that the option_value for the stylesheet option_name is sidenavigation. You can simply double-click the option_value field to change its value.
In this case, we have set the value to twentytwentyfour. This is the name of the directory in which the theme is installed within the themes directory.
You can find the right value to use for a theme by navigating to the wp-content/themes/ directory in your control panel’s file manager.
The image below shows the themes installed on a website.
After setting the appropriate value for the stylesheet row, you should now search for the template row in the options table. You can do so by filtering the rows with the word “template”.
Now, double-click the option_value for the option_name template. Enter twentytwentyfour as the new value.
Once you have updated the value of stylesheet and template options, you should have a new theme active on your website.
Change WordPress theme through the database in MySQL CLI
You can also change your active WordPress theme directly by executing some MySQL commands in the terminal.
Before you can execute any commands to update the database, you will need to authenticate yourself using your database login details.
The credentials you need to log in can be found in your site’s wp-config.php file.
Side note: This file also contains a lot of other sensitive information. You might want to read our guide on securing your WordPress wp-config.php configuration file to improve your WordPress site’s security.
Open the terminal to execute MySQL commands
First, open the terminal from your cPanel dashboard. You can find it under the Advanced section.
Authenticate yourself in the terminal
Execute the following command to authenticate yourself and log in to your MySQL database.
mysql -u database_username -p
Make sure you replace “database_username” with your actual database username. You can find this value in the wp-config.php file, as we mentioned earlier.
The terminal will prompt you to enter your password once you execute the above command. After entering your password, you should see something like this:
Execute commands to update the theme
We will now select the database that contains our options table. We did this using phpMyAdmin in our first method to change the active theme. We are using the terminal to do so here.
Execute the following command to select the WordPress database.
USE database_name;
After selecting the database, you can change the value of template and stylesheet options in the options table by executing the following commands one by one.
UPDATE wp_options SET option_value = 'theme-slug' WHERE option_name = 'template';
UPDATE wp_options SET option_value = 'theme-slug' WHERE option_name = 'stylesheet';
Please keep in mind that the options table isn’t always called wp_options. It might have a different prefix. You can find the value of this prefix inside the wp-config.php file. Just look for a line like this:
$table_prefix = 'alwK_';
The above line means that the prefix for the options table is alwK_.
Once you have executed these commands successfully, your terminal should look like this:
You can also visit your site in a browser to confirm that the theme change was successful.
Change WordPress theme through the database in WP CLI
The WP-CLI tool is the official command-line tool for WordPress. It provides an easy way for you to change the active WordPress theme.
One advantage of using this method is that it doesn’t require you to log in to your MySQL database and execute multiple commands. You can execute a single command to change the theme, provided you have already installed WP-CLI on your server.
First, open the terminal in cPanel. It should be under the Advanced section.
Once the terminal is open, make sure that you are in your website’s root installation directory. You can use the command “cd”, which is short for “change directory”, to move to the root directory.
In our case, the root directory is public_html. However, it could be www for you. The root directory will have other directories like wp-includes in it. It will also have files like wp-settings.php and wp-activate.php.
You could also consult your web host’s support staff if you aren’t entirely sure about your website’s root directory. To navigate to our root directory public_html, we execute the following line in the terminal.
Using WP-CLI requires you to download the wp-cli.phar file to your website’s root directory. Make sure that the root directory contains the wp-cli.phar file. This file should be present on your server if you have installed WP-CLI.
Execute the following command to change the active WordPress theme for your website.
php wp-cli.phar theme activate twentytwentyfour
Again, the theme slug would be the directory that contains the theme files. In this case, we are activating the Twenty Twenty-Four theme.
The following image shows the result of executing this command in the terminal.
Other reasons for an inaccessible admin dashboard
In this tutorial, we mentioned how activating or updating a theme can make the admin dashboard inaccessible. This is usually due to the theme’s incompatibility with some plugins, server misconfiguration, improperly coded themes, and incorrect custom code.
However, there are a few other reasons that can make the admin dashboard inaccessible:
- Sometimes the admin dashboard can also become inaccessible after you update or activate a plugin. In such cases, you should consider manually disabling WordPress plugins to access the admin dashboard again.
- The admin dashboard can also become inaccessible when WordPress is having difficulty establishing a database connection. Usually, you can easily fix WordPress database connection errors once you figure out the root cause.
Common reasons for a database connection error are wrong database credentials, a corrupt database, corrupt files, or lack of user privileges.
Conclusion
In this tutorial, we discussed three different methods of changing your WordPress site’s active theme. If the WordPress admin dashboard is inaccessible, the most beginner-friendly way to change the active theme is through phpMyAdmin. If speed is your goal, you might be able to change the theme a little faster if you use WP-CLI, provided it is already installed on your website.
If your WordPress website’s admin dashboard becomes inaccessible due to a faulty theme, changing the active theme through any one of these three methods will make it accessible again.
Frequently Asked Questions
WordPress stores information about themes inside the wp_options table. Please keep in mind that the options table might have a different prefix than wp_.
Changing your WordPress theme through phpMyAdmin requires you to change the value of template and stylesheet options within the wp_options table.