Introduction
There are situations where we may not be able to access the WordPress admin panel due to various issues, such as a broken theme, plugin conflicts, or login problems.
In such cases, we can change the active WordPress theme directly from the backend using MySQL/MariaDB. This can be done through phpMyAdmin or the MySQL/MariaDB command line.
In this article, we will explain how to change the active WordPress theme from the backend.
Prerequisites
Before proceeding, make sure you have:
- A WordPress installation.
- SSH access to the server, or access to phpMyAdmin.
- MySQL/MariaDB command-line access, if required.
- The theme that you want to activate must already exist under:
wp-content/themes/
Implementation
Step 1: Access the WordPress Database
Log in to the server through SSH, or access the WordPress database using phpMyAdmin or the MySQL/MariaDB command line.
Before making any database changes, it is recommended to take a backup of the WordPress database.
Step 2: Identify the Theme
In this example, we are going to activate the twentysixteen theme.
Make sure the corresponding theme directory exists:
wp-content/themes/twentysixteen
If you want to activate a different theme, replace twentysixteen with the appropriate theme directory name.
Step 3: Update the WordPress Theme
Run the following queries against the WordPress database:
UPDATE wp_options SET option_value = 'twentysixteen' WHERE option_name = 'template';
UPDATE wp_options SET option_value = 'twentysixteen' WHERE option_name = 'stylesheet';
UPDATE wp_options SET option_value = 'twentysixteen' WHERE option_name = 'current_theme';
If your WordPress database uses a custom table prefix, replace wp_options with the appropriate table name.
For example, if the table prefix is wpabc_, use:
UPDATE wpabc_options SET option_value = 'twentysixteen' WHERE option_name = 'template';
UPDATE wpabc_options SET option_value = 'twentysixteen' WHERE option_name = 'stylesheet';
UPDATE wpabc_options SET option_value = 'twentysixteen' WHERE option_name = 'current_theme';
Step 4: Verify the Website
After executing the queries, access the WordPress website and verify that the new theme is active.
If the website is using caching, clear the relevant WordPress, server, or CDN cache before testing.
Conclusion
Changing the WordPress theme directly from the backend is useful when the WordPress admin panel is inaccessible. By updating the relevant values in the wp_options table, we can activate an existing theme without accessing the WordPress dashboard.
Always make sure that the theme directory exists under wp-content/themes/ and take a database backup before making direct database changes.
FAQs
1. Can I change the WordPress theme without accessing the WordPress admin panel?
Yes. The active theme can be changed directly through the WordPress database using phpMyAdmin or the MySQL/MariaDB command line.
2. Where are WordPress themes stored?
WordPress themes are normally stored under:
wp-content/themes/
3. What should I replace twentysixteen with?
Replace twentysixteen with the theme directory name of the theme you want to activate.
For example:
UPDATE wp_options SET option_value = 'astra' WHERE option_name = 'template';
Related Article
How to do WordPress website migration from domain to subdomain – Pheonix Solutions
How to reset the WordPress password in Mysql – Pheonix Solutions
Talk to our experts
Have a technology challenge or looking for the right solution for your business? Our team can help you with cloud, DevOps, development, infrastructure, design, and more. Feel free to reach out to our experts here.