Sometimes your WordPress admin dashboard becomes inaccessible, the site breaks after a theme update, or a corrupted functions.php file locks you out. In such cases, switching themes through wp-admin becomes impossible.
The good news?
You can safely change your WordPress theme directly from the database — even when wp-admin is broken.
This guide teaches you exactly how to do that, including:
-
How WordPress stores theme data in the database
-
How to switch themes safely using phpMyAdmin
-
Exact SQL queries to update your theme
-
How to avoid theme-breaking errors
-
How to fix “Theme not found”
-
How to activate a child theme
-
Best practices when switching via the database
-
FAQs + schema markup
Let’s dive in.
Why You May Need to Change WordPress Theme via Database
There are legitimate situations where switching themes from the database is safer — or the only option:
1. Your WordPress admin dashboard is inaccessible
-
White screen of death
-
“Critical Error”
-
Plugin conflict
-
Fatal theme error
If you can’t open /wp-admin, the database method is your rescue.
2. Theme update or code changes broke the site
A broken functions.php or template file can take the whole site down. Switching themes resets the front-end to a functional state.
3. Theme folder was renamed or deleted
If the active theme folder is missing, WordPress cannot load it — causing errors.
4. Migrating site from staging to live
Sometimes theme paths or directories break during migration.
5. Need to force a child theme or parent theme activation
Useful when:
-
Parent theme updated
-
Child theme broken
-
Need to reset to parent theme
How WordPress Stores Theme Data in the Database
WordPress uses two important values inside the database to define the active theme:
| Database Table | Option Name | Purpose |
|---|---|---|
wp_options |
template |
The parent theme folder |
wp_options |
stylesheet |
The child theme folder (or same as template if no child theme) |
Example:
If your theme folder is:
Then:
-
template=astra -
stylesheet=astra
If you’re using a child theme:
Then:
-
template=astra -
stylesheet=astra-child
These values are what we change through phpMyAdmin.
How to Safely Change Your WordPress Theme via Database (Step-by-Step)
This is the safest and most complete guide you’ll find.
STEP 1: Identify Available Themes
Before changing anything, confirm which theme folders actually exist.
Login to your hosting → go to File Manager → open:
You should see something like:
-
astra
-
astra-child
-
twentytwentyfour
-
generatepress
-
kadence
Choose the theme folder name, not the display name.
STEP 2: Open phpMyAdmin
In your hosting panel (cPanel, CyberPanel, Plesk, SiteGround, NameHero, Hostinger):
Go to:
Databases → phpMyAdmin
Select your website’s database.
STEP 3: Open the wp_options Table
Find:
(Note: Your prefix might be wp3_options or custom.)
STEP 4: Locate template and stylesheet
Use the search box above the table.
Search for:
Then search:
STEP 5: Update Both Values
Click Edit on each row.
Replace the values with the new theme folder name.
Example: Switching to Astra
Example: Switching to a Child Theme
Important:
You MUST set template to the parent theme name even if using a child theme.
Method 2 — Change WordPress Theme Using SQL Query (Fastest)
If you prefer direct SQL, use:
Child theme example:
Avoid These Common Mistakes
Mistake 1: Using the theme display name instead of folder name
Correct: astra
Wrong: Astra Theme, Astra Pro
Mistake 2: Changing only stylesheet
Both must match.
Mistake 3: Parent theme not installed
If you set:
…but /wp-content/themes/astra does not exist → Site will break.
Mistake 4: Wrong database prefix
Your site may use:
wp2_optionssite_options
Always check prefix.
Troubleshooting (Fix Any Error After Switching Theme)
1. “The theme directory does not exist”
Check:
Ensure theme folder exists. Re-upload if missing.
2. White screen after changing theme
Add this to wp-config:
Check:
3. Child theme error (parent theme missing)
Fix by setting:
4. Cannot access phpMyAdmin
Use WP-CLI:
5. SQL error: “Table not found”
Verify correct prefix:
Best Practices When Switching Themes via Database
Always backup database
Use your hosting panel.
Test theme first on staging site
Never switch directly on production during peak hours.
Re-save permalinks after switching
Go to:
Settings → Permalinks → Save
Regenerate thumbnails
Use plugin: Regenerate Thumbnails Advanced
Disable caching/CDN temporarily
Cloudflare + LiteSpeed + WP Rocket can serve cached CSS.
Delete old theme customizer values (optional)
FULL VIDEO-STYLE WALKTHROUGH (TEXT VERSION)
Here is a simple narrative flow your readers will appreciate:
1. Login to your hosting dashboard
Most users will use cPanel/Hostinger/NameHero.
2. Open File Manager → themes folder
Confirm theme folder names.
3. Open phpMyAdmin → select database
4. Edit template + stylesheet rows
Paste the new theme folder names.
5. Save changes and reload website
Your site will now load with the new theme.
Code Snippet: PHP Theme Switch (Alternative Method)
If you want to force switch via a temporary PHP file:
Save as:
And run:
Delete file afterward.
FAQs: How to Safely Change WordPress Theme via Database
1. Is it safe to change WordPress theme from the database?
Yes — if you update both template and stylesheet correctly and ensure the theme folder exists.
2. What happens if I put the wrong theme name?
Your site may break temporarily, but correcting it in the database fixes the issue instantly.
3. Can I activate a child theme from the database?
Yes. Set:
4. Will my customizer settings be lost?
No. WordPress stores them separately unless you delete theme_mods manually.
5. Does this work if wp-admin is completely down?
Yes. This is the primary method to recover a broken wp-admin after theme issues.
6. Can I switch themes using WP-CLI instead of phpMyAdmin?
Yes:
7. Will plugins break after switching themes?
Only if the theme depended on custom code. Usually everything continues working.
8. Does database switching affect widgets or menus?
Widgets will reset, but menus remain saved (may need to reassign menu locations).