How to Fix Critical Error on Your WordPress Website with Solutions
Posted in: PHP, Security, WordPress

How to Fix a Critical Error on Your WordPress Website with Solutions

If you have a WordPress website, you may encounter errors from time to time. A critical error can appear unexpectedly or randomly on your site. It can potentially make your WordPress website partially or entirely inaccessible.

In this guide, you will learn how to troubleshoot a critical error on your WordPress website. First, you will learn how to identify the source or reason for an error, and then you will learn the steps needed to fix it.

Reasons for Errors in WordPress and How to Fix Them

There can be many reasons or causes for an error in a WordPress website. Here, we will go through them one by one. Also, you will learn how to troubleshoot and fix the error.

Critical Error After Upgrading a WordPress Plugin or Theme

Upgrading a WordPress plugin or theme can sometimes lead to a critical error. The error may arise due to conflicts with the current WordPress version, other plugins, or theme.

If you haven’t upgraded any plugin or theme on your own, then you may have auto-upgrade enabled for some or all of your plugins or themes. As a result, they automatically upgraded which can also cause incompatibility issues with your current WordPress environment.

Ultimately, these upgrade-related incompatibilities often trigger critical errors and break your website’s access. To regain access and fix the critical error, you need to find and deactivate the problematic plugins or theme. If you’ve lost admin access to the WordPress dashboard, you can still deactivate plugins/themes using your file manager.

The general process of troubleshooting involves three main steps:

  1. Deactivate the problematic plugin or theme via File Manager or FTP.
  2. Upgrade the plugin or theme to the latest or compatible version.
  3. Reactivate the plugin or theme after upgrading.

First of all, make sure you have access to your WordPress website files. For this, you may use your cPanel’s file manager tool or FTP. There, in the root directory of your WordPress files, you will find the “wp-content” folder.

Deactivate all Plugins at Once

To quickly deactivate all the active plugins at once, you can rename the “plugins” folder in “wp-content/plugins” to something like “wp-content/plugins-old“. Then try logging into your WordPress admin. This should deactivate all plugins and potentially resolve the critical error.

Once, you see that all plugins are deactivated, you can rename the “plugins-old” directory back to its original name “plugins” in “wp-content/plugins” using the file manager. Renaming to the original name will not reactivate the plugins on its own. You would need to return to WordPress admin and then reactivate plugins one by one to identify the problematic one.

Deactivate One Plugin At a Time

To deactivate a specific plugin via file manager, locate its folder in “wp-content/plugins”. For example, to deactivate WP Fastest Cache, rename “wp-content/plugins/wp-fastest-cache” to “wp-content/plugins/wp-fastest-cache-old“. After, you can navigate to the WordPress admin panel and the plugin should be deactivated.

Once you see that the intended plugin is deactivated, you can rename its directory to the original name, that is “wp-content/plugins/wp-fastest-cache“. This will not reactivate the plugin on its own. You would need to activate it again by going to the WordPress admin panel. Before activating it, you can update the plugin to a newer version if available.

You can check the plugin’s official website for its version compatibility with your WordPress version and PHP version, upgrade if needed, and reactivate after the upgrade.

Deactivate the Currently Active Theme

Unlike plugins, only one theme can be active at a time. To deactivate your current theme, similar steps are needed. Locate its folder in “wp-content/themes”. For example, if your currently active theme is StoreFront, then you can rename “wp-content/themes/storefront” to “wp-content/themes/storefront-old“.

This will deactivate the StoreFront theme and revert to the default theme. You can then rename the theme directory name to its original name, from “storefront-old” to “storefront” in “wp-content/themes/storefront“. This will not reactivate the theme on its own. First, check theme compatibility from its official website, upgrade if required, and then reactivate.

The key steps are deactivating the suspect plugins or theme, upgrading any incompatible versions, and selectively reactivating to pinpoint and resolve the critical error. File manager access allows you to deactivate even when you can’t access your WordPress admin panel.

Incompatible Code of a Plugin or Theme Result in an Error

If upgrading the problematic plugin or theme does not resolve the critical error, you’ll need to pinpoint the exact problematic code. This can be done by enabling WordPress debug mode to view details in the “debug.log” file.

Enabling Debug Mode and Checking the Debug.log

To enable debug mode, open the “wp-config.php” file in the root of your WordPress installation files. You can find this PHP code in “wp-config.php”.

define( 'WP_DEBUG', false );

Add or modify the above PHP code in “wp-config.php” to:

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );

Now, it will start to log any new error that you get when you visit the page again. So, you would need to visit the page on your website where you see the critical error.

This will generate a “debug.log” file in “wp-content/debug.log“. Then, you can open this “debug.log” file to view error messages with timestamps and originating file paths. This can help to identify the specific code causing fatal errors or a critical error.

You can now deactivate the problematic plugin or theme as outlined before.

Alternatively, you may want to reach out to the developer of that plugin or theme to notify them of the issue. Or you can attempt a quick code fix yourself if experienced with PHP or WordPress development.

After identifying and resolving the error, remember to disable debug mode by setting:

define( 'WP_DEBUG', false );
define( 'WP_DEBUG_LOG', false );

Leaving debug mode on can expose sensitive information and impact performance. But it’s a useful tool for drilling down on specific errors when upgrading WordPress components like plugins and themes. The debug.log provides details to pinpoint problematic code triggering a critical error on your WordPress site.

Theme or Plugin Compatibility with PHP Version

Upgrading your PHP version can also trigger a critical error on your WordPress site if your plugins or theme are not compatible with the new PHP release. This may happen if your host automatically upgrades PHP or you manually upgrade it yourself. In this case, affected plugins or the theme will break on the new PHP version running WordPress.

The solutions here are to either downgrade PHP to a compatible version or upgrade your plugins/themes to the latest releases that support the new PHP version. You can check the plugin/theme’s official websites to verify PHP compatibility.

Potential actions you can take:

  • Current PHP Version: Check your current PHP version by accessing cPanel or going to the WordPress admin panel and navigating to the menu, “Tools” > “Site Health” > “Info”.
  • Downgrade or Upgrade PHP Version: Contact your hosting provider or use cPanel to downgrade or upgrade the PHP version to a compatible one.
  • Upgrade Plugins or Theme: Update all of your plugins and your current theme to their latest versions and ensure PHP compatibility.

Stuck Displaying Schedule Maintenance Notice “Briefly unavailable for scheduled maintenance”

Besides a critical error, a few other cases can make your WordPress site inaccessible.

Sometimes a WordPress site gets stuck displaying a “Briefly unavailable for scheduled maintenance” message. This is caused by a “.maintenance” file added to the WordPress root folder, putting the site in maintenance mode.

WordPress Notice - Briefly unavailable for scheduled maintenance
WordPress Notice – Briefly unavailable for scheduled maintenance

To resolve this:

  • Locate “.maintenance” File: Use your file manager or FTP to access the WordPress file directory. Check for a “.maintenance” file in the root directory of your WordPress files.
  • Delete “.maintenance” File: Once you locate the “.maintenance” file, delete it. This will remove the maintenance message and take your website out of maintenance mode.

The “.maintenance” file triggers maintenance mode when present in the root directory of your WordPress website files. Simply deleting this “.maintenance” file can quickly take a WordPress site out of maintenance mode if unintentionally added or if it fails to remove properly after scheduled maintenance.

WordPress Website Shows Critical Error Sometimes “There has been a critical error on this website.”

A critical error in WordPress can occur by an incompatible plugin, theme, or corrupted file. We have already mentioned the reasons for a critical error and how to fix a critical error.

Website Shows Critical Error Randomly Due to High Memory Usage or High I/O Usage

There are also cases when you may get critical errors on your WordPress site randomly, typically caused by high memory usage or high I/O usage. This issue is often the result of poorly coded plugins or themes.

WordPress Error - There has been a critical error on this website
WordPress Error – There has been a critical error on this website

To address this problem, you can take the following steps:

  • Increase Memory Limit or I/O Limit: Use cPanel or contact your hosting provider to increase the memory limit or I/O limit for your WordPress website.
  • Replace Poorly Coded Plugins or Themes: Find which plugin or theme is responsible for high memory or high I/O usage by deactivating them one by one. This way, you can isolate the poorly coded plugin or theme and upgrade or replace them.

If you’re specifically dealing with high memory usage in a WordPress site, we have a detailed guide on how to fix high memory usage issues that you may find helpful.

Fixing Database Issue “Error establishing a database connection”

When you get the error message “Error establishing a database connection” on your WordPress website, it typically indicates one of two issues. Either your database service, such as MySQL or MariaDB server, is not running, or your database credentials are incorrect.

WordPress - Error establishing a database connection
WordPress – Error establishing a database connection

To resolve this issue, follow these steps:

  • Check Database Service: Make sure that your database service, such as MySQL or MariaDB server, is running. You can do this by accessing your hosting provider’s control panel or contacting their support for assistance.
  • Verify Database Credentials: Locate the “wp-config.php” file in the root directory of your WordPress files. Open the “wp-config.php” file and make sure the database credentials are correctly specified in this file. Here, make sure the database name, username, password, and host are correct.

In some instances, the “Error establishing a database connection” error can occur due to MySQL running out of available memory. This situation can arise when the database server is handling a large number of concurrent connections, complex queries, or dealing with extensive data sets. When MySQL’s memory limit is reached, it may prevent new connections from being established, including the connection attempt made by WordPress.

To address this issue, first, identify if MySQL’s memory limit is indeed the culprit by checking the server’s error logs or MySQL’s status variables. Look for entries or messages related to “out of memory” or “too many connections” errors. If the memory limit is the root cause, there are a few potential solutions:

  • Optimize MySQL queries and database structure: Examine your WordPress plugins and current theme for inefficient queries or poorly optimized database structures.
  • Implement query caching: Use object cache like Redis to cache database query results. Enabling query caching in MySQL can help reduce the load on the database server by storing frequently accessed query results in memory.
  • Upgrade database server: Upgrade your database server’s resources (CPU, RAM, etc.) or scale to a better server configuration to handle the increased memory demands.

Conclusion

For a WordPress site owner, it is frustrating to see a critical error. Critical errors can occur for various reasons, such as upgrading WordPress core, plugins, or themes, compatibility issues with PHP versions or other plugins, and high memory or high I/O usage. There are quick and easy ways to recover from a critical error and identify its cause, as outlined in our guide. In addition, we’ve covered other potential issues that can make a WordPress site inaccessible, such as being stuck in maintenance mode or facing a database connection error, along with actionable steps to resolve them.

Back to Top