Change WordPress Theme from Database: Step-by-Step
In this article
If you're locked out of your WordPress admin dashboard or your site is showing a fatal error, you can still switch themes directly through the database. This method is a reliable fallback that works by updating a few option values in the wp_options table. It's a straightforward process, but you need to be careful—a wrong edit can break your site further. This guide walks you through the exact steps, what to watch out for, and how to recover if something goes wrong.
What You'll Need
- Access to your hosting control panel (cPanel, Plesk, or similar) or a database management tool like phpMyAdmin, Adminer, or MySQL Workbench.
- Your database host, username, and password (usually found in your
wp-config.phpfile). - FTP or file manager access to your server (as a backup, in case you need to manually edit files).
- The exact folder name of the theme you want to activate (e.g.,
twentytwentyfour). This is usually the folder name inside/wp-content/themes/.
Step-by-Step
- Back up your database. Before making any changes, export a full backup of your database. In phpMyAdmin, select your database, click the "Export" tab, and choose the "Quick" method. Save the file to your computer. This is your safety net—if anything goes wrong, you can restore it.
- Log in to phpMyAdmin. Go to your hosting control panel and find the phpMyAdmin icon (or your preferred database tool). Click it to open the interface.
- Select your WordPress database. On the left sidebar, you'll see a list of databases. Click the one that corresponds to your WordPress site. If you're not sure which one, check your
wp-config.phpfile for theDB_NAMEconstant. - Open the
wp_optionstable. After selecting the database, you'll see a list of tables. Click onwp_options(if your table prefix is different, it will be something likeyourprefix_options). This table stores all your site's settings, including the active theme. - Find the
templateoption. In thewp_optionstable, look for the row whereoption_nameistemplate. You can use the search box at the top to filter. Click the "Edit" (pencil) icon on that row. - Change the
templatevalue. In the edit form, locate theoption_valuefield. Replace the current value with the folder name of the theme you want to activate. For example, if you want to switch to the default Twenty Twenty-Four theme, typetwentytwentyfour. Click "Go" or "Save" to update. - Find the
stylesheetoption. Go back to the table and find the row whereoption_nameisstylesheet. Edit it the same way. - Change the
stylesheetvalue. Set theoption_valueto the exact same folder name you used fortemplate. This is crucial—both must match. Save the change. - Clear any caching. If you have a caching plugin (like W3 Total Cache or WP Super Cache), the old theme might be cached. After updating the database, go to your site and hard-refresh (Ctrl+F5 on Windows, Cmd+Shift+R on Mac). If you have server-side caching, you may need to purge it from your hosting control panel.
- Verify your site. Visit your site's front page. It should now display the new theme. Also, try logging into
/wp-admin—you should see the new theme's dashboard styling.
Common Mistakes
- Mismatched template and stylesheet values. If these two don't match, WordPress may show a broken site or a "The theme is broken" error. Always set both to the same folder name.
- Using the theme's display name instead of the folder name. The option value must be the folder name (e.g.,
twentytwentyfour), not the pretty name (e.g., "Twenty Twenty-Four"). - Editing the wrong row. Make sure you're editing the row where
option_nameis exactlytemplateorstylesheet, not something similar liketemplate_version. - Forgetting to back up. Skipping the backup can turn a small mistake into a disaster. Always export before editing.
- Activating a theme that isn't installed. If the folder name you type doesn't exist in
/wp-content/themes/, WordPress will fall back to the default theme, but you might see errors. Double-check that the theme is actually present.
Tips
- Use the default theme as a safe fallback. If you're unsure, switch to a default WordPress theme like
twentytwentyfour(or whatever is installed). These are always present in a standard installation. - Test on a staging site first. If you have a staging environment, try the database method there before touching your live site.
- Keep your table prefix in mind. If you changed the default
wp_prefix for security, adjust the table name accordingly. - Use a SQL query if you're comfortable. Instead of clicking through the interface, you can run a direct SQL query:
UPDATE wp_options SET option_value = 'your-theme-folder' WHERE option_name IN ('template', 'stylesheet');This is faster and less error-prone if you're confident.
Troubleshooting
My site is completely white (blank page) after the change.
This usually means the theme folder name you entered doesn't exist or is incorrect. Go back to phpMyAdmin and double-check the folder name in /wp-content/themes/. If it's wrong, correct it. If the site is still blank, restore your database backup.
I see "The theme is broken" error.
This often happens when the template and stylesheet values don't match. Ensure both are set to the same folder name. Also, check that the theme's style.css file exists in that folder—if it's missing, WordPress can't load the theme.
My admin dashboard is still showing the old theme.
Clear your browser cache and any caching plugins. If you have a caching plugin, deactivate it temporarily via FTP (rename the plugin folder) or via the database (set the plugin's active_plugins option to an empty array). Then check again.
I can't access phpMyAdmin.
If your host doesn't provide phpMyAdmin, you can use a command-line tool like MySQL via SSH, or a desktop client like MySQL Workbench. Alternatively, you can temporarily rename the current theme's folder via FTP—WordPress will automatically fall back to the default theme. This is a simpler but less direct method.
I changed the values but nothing happened.
Make sure you saved the changes (clicked "Go" or "Save"). Also, verify that the option names are exactly template and stylesheet—some plugins or custom code might have altered the options table. Look for any transients or cache options that might be overriding the theme.
Frequently Asked Questions
Q: Can I change the theme from the database if I'm locked out of wp-admin?
Yes, that's the main reason to use this method. As long as you have database access, you can switch themes even if you can't log in.
Q: What if I don't know the exact folder name of the theme I want?
Check the /wp-content/themes/ directory via FTP or your hosting file manager. Each folder there is a theme, and the folder name is what you use in the database.
Q: Is it safe to edit the database directly?
It's safe if you back up first and only change the two specific options. Editing other options can cause serious issues, so stick to the steps above.
Q: Will this work for a multisite network?
Yes, but you need to edit each site's options table separately. In a multisite, each site has its own options table (e.g., wp_2_options for site ID 2).
Q: Can I use this method to activate a premium theme I just uploaded?
Yes, as long as the theme's folder is in /wp-content/themes/. The database method will activate it exactly like the admin panel would.
Q: What if I want to switch back to my old theme?
Simply repeat the process and set the template and stylesheet values back to the old theme's folder name. If you have a backup, you can also restore it.