Skip to content
ThemesIonic — home
Troubleshooting

Switching Off a Broken Theme From the Database

Two rows in wp_options, template and stylesheet, decide which theme loads. Point them at an installed theme and the site is back. Point them at a folder that does not exist and visitors get an empty page with status 200 until someone opens Appearance › Themes.

Updated 5 min read advanced

Set the template and stylesheet rows in the options table to the folder name of a theme that is installed, and WordPress loads that theme on the next request. That is the whole database fix. The risk is not the query but the value you put in it: a folder name that does not exist leaves visitors looking at an empty page.

What WordPress does with a theme folder that does not exist

On a WordPress 7.1.5 test site we pointed both options at a folder that was not there and requested the site three ways:

Request Result
Home page, logged out HTTP/1.1 200 OK, body of 0 bytes
Home page, logged in as administrator HTTP 500, The theme directory "bb-missing-theme" does not exist.
/wp-admin/ dashboard Loads normally
Appearance › Themes The active theme is broken. Reverting to the default theme. and the switch happens

The empty 200 is the dangerous part: no error message for visitors, and search engines receive a successful blank page. It comes from the template loader, which finds no template to include and only calls wp_die() with the theme error for users who can switch themes.

WordPress repairs the state only in validate_current_theme(), which runs on Appearance › Themes and in the Customizer. It switches to WP_DEFAULT_THEME — twentytwentyfive in 7.1.5 — if that folder exists, otherwise to the newest bundled default theme that is installed. With no default theme installed it cannot fix anything.

A missing child with a working parent behaves differently: with stylesheet pointing at a missing folder and template at an installed block theme, the site kept rendering from the parent. A broken child can stay unnoticed for a long time.

Try these before the database

  1. Recovery Mode. When a theme causes a fatal error, WordPress emails the administrator a link that opens wp-admin with the theme paused. Check the inbox and spam first.
  2. Rename the theme folder over SFTP or the file manager, for example wp-content/themes/broken-theme to broken-theme-off. The theme's functions.php stops loading, so wp-admin works again. Then go straight to Appearance › Themes: that visit is what switches the site to the default theme. Until you do it, visitors get the empty page described above. If a child theme is active, rename the child unless the parent is the broken one.
  3. WP-CLI, if you have SSH. Without extra flags it loads the active theme too, and a theme with a fatal error stops it:
$ wp theme list
Error: There has been a critical error on this website.

Uncaught Error: Call to undefined function bb_undefined_function_call() in .../wp-content/themes/bb-broken-theme/functions.php:2

With --skip-themes the same command ran and listed the themes, so use it for the switch as well:

wp --skip-themes theme list
wp --skip-themes theme activate twentytwentyfive

wp theme activate goes through switch_theme(), which also runs the theme switch hooks and remaps widgets and menu locations — things the raw SQL below skips.

What the database stores

The table is named with the prefix from wp-config.php: wp_options by default, often something else. On multisite each site has its own table (wp_2_options and so on).

Option name What it holds
stylesheet Folder name of the active theme; the child if a child theme is active
template Folder name of the parent theme; same as stylesheet for a standalone theme
current_theme Display name, a label only; WordPress does not use it to load the theme

These are folder names, not display names: "Twenty Twenty-Five" lives in twentytwentyfive. On Linux they are case-sensitive.

Back up, then run the query

Export the options table (phpMyAdmin › Export, or mysqldump) before changing it; a mistyped WHERE rewrites every row and there is no undo. A full backup is better still.

Confirm the target folder exists under wp-content/themes/, read the current values, then update both rows:

SELECT option_name, option_value FROM wp_options
WHERE option_name IN ('template', 'stylesheet');

UPDATE wp_options
SET option_value = 'twentytwentyfive'
WHERE option_name IN ('template', 'stylesheet');

Run against a copy of our test database, MariaDB answered:

Query OK, 2 rows affected
Rows matched: 2  Changed: 2  Warnings: 0

Anything other than Rows matched: 2 means the prefix or option names are wrong. Running it a second time reports Changed: 0, which is harmless. The current_theme row still said Twenty Twenty-Five from before; it does not need editing.

Note the old values before you overwrite them, so you can put the original theme back once it is fixed.

Afterwards

  • Flush the caches. A persistent object cache serves the old options until flushed; wp cache flush or the hosting panel does it. A page cache or CDN keeps the old HTML.
  • Open Appearance › Themes once. It confirms the active theme and, if the value you wrote was wrong, triggers the automatic revert rather than leaving visitors on a blank page.
  • If you also cannot log in, add an administrator through phpMyAdmin. If wp-admin fails for other reasons, see wp-admin not working.
  • Find out why the theme broke: the error log usually names a functions.php line or a PHP version incompatibility. Call to undefined function and syntax errors are the usual two. A theme that is incomplete on disk shows the stylesheet is missing instead.

Common mistakes

  • Writing the display name ("Twenty Twenty-Five") instead of the folder name.
  • Renaming the folder and walking away: the site stays blank for visitors until someone opens Appearance › Themes.
  • Changing only stylesheet when a child theme was active, leaving the broken parent in template.
  • Editing the wrong table on a site with a custom prefix, or the main site's table on multisite.
  • Editing the options of a damaged database; if tables report errors, repair the database first.

Verify

  • The SELECT above returns the new folder name in both rows.
  • The home page, loaded logged out in a private window, returns HTML, not an empty 200: curl -s https://example.com/ | wc -c is far above zero.
  • Appearance › Themes shows the theme you set as active, with no "broken" notice.

Frequently asked

stylesheet holds the folder name of the active theme and template holds the folder name of its parent. For a standalone theme both are the same. When a child theme is active, stylesheet is the child and template is the parent. Set both to the same standalone theme to switch off a child and its parent at once.
Not for visitors. On WordPress 7.1.5 a missing theme folder gave visitors an empty page with status 200 and logged-in administrators a 500 error saying the theme directory does not exist. WordPress only reverts to the default theme when someone opens Appearance › Themes or the Customizer, where it shows "The active theme is broken. Reverting to the default theme."
Usually a cache. A persistent object cache keeps the autoloaded options in memory, so WordPress keeps reading the old theme until the cache is flushed, and a page cache or CDN keeps serving the old HTML. Also check the table prefix: if the site uses something other than wp_, the query ran against a table WordPress does not read.

Related guides