# Fix WordPress Theme Breaks Site

Your WordPress theme just updated, or you activated a new theme, and now your site is broken. White screen, fatal error, missing layout, or functions not working. The theme is the culprit, and you need to recover quickly.

Theme issues are often more dramatic than plugin issues because themes control the entire visual layer. A broken theme means a broken site, not just broken functionality.

Emergency Recovery: Get Your Site Back Now

If your site is completely down and you need immediate access:

Method 1: Switch Theme via WP-CLI

```bash # Switch to a default WordPress theme wp theme install twentytwentyfour --activate

# Or if you know another working theme wp theme activate classic-theme-name ```

Method 2: Switch Theme via FTP

```bash # Connect via FTP or SSH cd wp-content/themes/

# Rename the broken theme mv broken-theme broken-theme-disabled

# WordPress will fall back to a default theme # If no default exists, install one ```

Method 3: Switch Theme via Database

```sql -- In phpMyAdmin or MySQL CLI -- Find current theme SELECT option_value FROM wp_options WHERE option_name = 'template'; SELECT option_value FROM wp_options WHERE option_name = 'stylesheet';

-- Switch to a default theme (twentytwentyfour) UPDATE wp_options SET option_value = 'twentytwentyfour' WHERE option_name = 'template'; UPDATE wp_options SET option_value = 'twentytwentyfour' WHERE option_name = 'stylesheet'; UPDATE wp_options SET option_value = 'twentytwentyfour' WHERE option_name = 'current_theme'; ```

Method 4: Force Theme via wp-config.php

php
// Add to wp-config.php
define('WP_DEFAULT_THEME', 'twentytwentyfour');

This forces WordPress to use the specified theme regardless of database settings.

Identify the Theme Problem

Once you've recovered access, diagnose what went wrong.

Check for PHP Errors

```bash # Enable debugging if not already # In wp-config.php: define('WP_DEBUG', true); define('WP_DEBUG_LOG', true);

# Check the debug log tail -50 wp-content/debug.log

# Look for theme-related errors grep -i "themes/broken-theme" wp-content/debug.log | tail -20 ```

Check Theme Compatibility

```bash # Check your WordPress version wp core version

# Check theme requirements wp theme get broken-theme --fields=name,version,requires,requires_php

# Check PHP version php -v wp eval 'echo "PHP: " . phpversion() . "\n";' ```

Theme errors often stem from:

  • PHP version mismatch (theme requires PHP 8.0+, you have 7.4)
  • WordPress version mismatch (theme uses new features)
  • Missing required plugins (many themes require companion plugins)

Validate Theme Files

```bash # Check theme has required files ls -la wp-content/themes/broken-theme/

# Must have: style.css and index.php # Check style.css header head -20 wp-content/themes/broken-theme/style.css ```

A valid theme needs at minimum:

  • style.css with proper header comment
  • index.php template file

Check for Syntax Errors

```bash # PHP syntax check on theme files find wp-content/themes/broken-theme -name "*.php" -exec php -l {} \; 2>&1 | grep -v "No syntax errors"

# Check functions.php specifically (common source of errors) php -l wp-content/themes/broken-theme/functions.php ```

Common Theme Errors

1. Fatal Error: Uncaught Error

bash
Fatal error: Uncaught Error: Call to undefined function some_function()
in /wp-content/themes/broken-theme/functions.php on line 45

The theme calls a function that doesn't exist (removed in newer PHP, or missing plugin dependency).

Fix:

```bash # Find what's calling the function grep -r "some_function" wp-content/themes/broken-theme/

# Either add the missing function, or remove the call # Check if it's a plugin dependency wp plugin list --status=active ```

2. White Screen After Theme Update

Theme updated and now shows white screen.

Diagnosis:

```bash # Check error log tail -100 wp-content/debug.log | grep -i "fatal|error"

# Common cause: functions.php syntax error php -l wp-content/themes/updated-theme/functions.php

# Or: theme uses deprecated WordPress functions grep -r "deprecated_function" wp-content/debug.log ```

3. Layout Broken / CSS Not Loading

Theme loads but looks broken.

Diagnosis:

```bash # Check if style.css exists and has content ls -la wp-content/themes/broken-theme/style.css

# Check CSS is being loaded curl -I https://yourdomain.com/wp-content/themes/broken-theme/style.css

# Should return 200 OK, not 404 or 403 ```

Common causes:

  • Incorrect theme folder name after upload
  • File permissions blocking CSS access
  • .htaccess blocking static files
  • CDN caching old CSS

Fix:

```bash # Check and fix permissions chmod 644 wp-content/themes/broken-theme/style.css chmod 755 wp-content/themes/broken-theme/

# Check .htaccess for blocks grep -i "deny|forbidden" .htaccess

# Clear any caching wp cache flush wp rewrite flush ```

4. Missing Template Files

bash
Warning: require_once(/wp-content/themes/broken-theme/inc/template-tags.php): 
failed to open stream: No such file or directory

Fix:

```bash # Check what files theme expects grep -r "require|include" wp-content/themes/broken-theme/functions.php

# Reinstall theme if files are missing wp theme delete broken-theme wp theme install broken-theme --activate ```

5. Theme Requires Plugin

Many themes require companion plugins for full functionality.

Symptoms:

  • "Install required plugins" notice
  • Missing shortcodes displayed as text
  • Layout elements not rendering

Fix:

```bash # Check for TGMPA plugin recommendations grep -r "tgmpa|TGM_Plugin_Activation" wp-content/themes/broken-theme/

# Install recommended plugins # Usually listed in Appearance -> Install Plugins ```

Theme Customization Recovery

If you had customizations in the broken theme:

Child Theme Content

```bash # Check if child theme exists ls -la wp-content/themes/broken-theme-child/

# Child theme customizations are preserved # Activate parent theme fix, then reactivate child ```

Custom CSS

```bash # Check Additional CSS in database wp option get wp_custom_css

# Or check theme mods wp option get theme_mods_broken-theme ```

Customizer Settings

```bash # Export customizer settings wp export --post_type=customize_changeset --dir=/tmp/customizer-backup

# Or check theme mods wp eval 'print_r(get_theme_mods());' ```

Fix the Theme Itself

If you want to fix rather than replace the theme:

Fix PHP Errors

```bash # Locate the error line # If functions.php line 123 has error: sed -n '120,125p' wp-content/themes/broken-theme/functions.php

# Edit to fix or comment out problematic code # Use FTP or WP-CLI edit: wp theme mod set broken-theme custom_css "/* Add working CSS */" ```

Fix Missing Functions

php
// In functions.php, add missing function check
if (!function_exists('some_missing_function')) {
    function some_missing_function() {
        // Stub implementation or return
        return;
    }
}

Fix Deprecated Code

```bash # Find deprecated WordPress functions grep -r "get_settings|get_bloginfo|wp_print_scripts" wp-content/themes/broken-theme/

# Replace with modern equivalents: # get_settings() -> get_option() # wp_print_scripts() -> wp_enqueue_scripts ```

Verify Theme Recovery

After switching or fixing:

```bash # Test frontend loads curl -I https://yourdomain.com

# Check no PHP errors wp eval 'echo "Theme loaded: " . wp_get_theme()->get("Name") . "\n";'

# Verify theme is valid wp theme list

# Run theme check wp theme verify-checksums broken-theme ```

Prevention Best Practices

Use a Child Theme

```bash # Create child theme mkdir wp-content/themes/broken-theme-child cat > wp-content/themes/broken-theme-child/style.css << 'EOF' /* Theme Name: Broken Theme Child Template: broken-theme */

@import url("../broken-theme/style.css");

/* Your custom CSS */ EOF ```

Test Updates on Staging

bash
# Never update theme directly on production
# Create staging copy first
wp db export production-db.sql
wp db create staging_db
# Configure staging environment

Backup Theme Settings

```bash # Export customizer settings wp eval 'echo json_encode(get_theme_mods());' > theme-mods-backup.json

# Backup theme files tar -czf theme-backup.tar.gz wp-content/themes/broken-theme/ ```

When a theme breaks your site, speed matters. Switch to a default theme, regain access, then diagnose at your own pace. Never try to fix a broken theme on a live site without a backup plan.