• Having a strange issue where my site keeps reverting back to the Twenty Twenty-One theme because WP think’s our custom theme is broken. Sometimes it’s the whole site, sometimes it’s only the homepage and all other pages keep using my custom theme as normal.

    When I go to wp-admin’s Themes section, my custom theme that I’ve used for years with no issues is still set to Active, however, there’s a note above it saying: “The active theme is broken. Reverting to the default theme.”

    Just looking for a quick fix here to get my site back to working normal while I investigate updating WP and my theme, so far I’ve tried:

    – Clearing/Removing all of my caching plugins

    – Manually changing the wp_options table’s template, stylesheet, and current_theme values to be my custom theme’s name (this seems to instantly fix the problem, but after a few hours it seems like WordPress reverts back to Twenty Twenty-One)

    – Deleting the Twenty Twenty-One theme from my server’s Themes folder (somehow even without a theme folder/files WP switches back to this theme)

    – Remove various code from the wp-includes/theme.php file that seem like would be checking for this “broken” state and causing the site to revert

    Is there anything I can add to my functions.php file or somewhere else to ensure that WordPress either doesn’t check for the theme being broken or forces my custom theme to always be used?

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator bcworkz

    (@bcworkz)

    Try editing wp-config.php, replacing the default WP_DEBUG definition with:

    define( 'WP_ENVIRONMENT_TYPE', 'development' );
    define( 'WP_DEBUG', true );
    define( 'WP_DISABLE_FATAL_ERROR_HANDLER', true );

    With this config, when I introduce an error into my active theme, WP simply crashes with an error message. It doesn’t switch themes.

    Important: Because WP can crash, you cannot use the theme editor! You must be able to update erroneous code via FTP or a file manager. This config is best in a local development environment but can work on a remote web server.

    This is not a suitable config for production. Define “production” environment and false for the other 2 when you’re done debugging.

    Thread Starter hypman

    (@hypman)

    Hey @bcworkz don’t know if that’s what I’m trying to accomplish here. My goal is that I just want to prevent WordPress from automatically switching to a different theme (since when it does display my correct custom theme the site works fine). I don’t want our site/WP to crash when it finds something it thinks is broken.

    Moderator bcworkz

    (@bcworkz)

    Apparently I’ve misunderstood. Apologies. Apparently your theme does not work fine in all cases. You need to attempt to determine what causes WP to decide it is suddenly broken. Perhaps a particular request that invokes certain code that’s not normally used? Try reviewing you access log for clues such as unusual requests. You can then try out anything unusual to see if it causes the theme to be switched.

    Being able to replicate the problem on demand is essential for isolating the problem.

    Thread Starter hypman

    (@hypman)

    The main error that it’s showing under the Themes is “Stylesheet is missing.”

    However, I have my style.css file in the theme’s root folder with the theme’s name correctly listed at the top of the style.css file. :/

    Moderator bcworkz

    (@bcworkz)

    Confirm the file’s permissions are correct via FTP. Intermittent failure to access a file indicates a server issue. You may need your host’s assistance to resolve this.

    Exact same thing is happening to me – you are not alone, and it’s driving me nuts. I’ve made heaps of custom themes over the years and never had this issue before.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to prevent WP from automatically reverting to Twenty Twenty-One Theme?’ is closed to new replies.