View Categories

How to identify and fix a “Critical Error” in WordPress

WordPress critical error

The “There has been a critical error on your website” message is one of the most common problems in WordPress. It usually occurs when a plugin or theme causes a conflict or there is a code error.

In this tutorial, you will learn how to identify the source of the problem using WordPress’s debugging mode, WP_DEBUG, and how to edit the wp-config.php file to enable this functionality.

Steps to identify and fix the problem

1. Enable WP_DEBUG

WP_DEBUG is a WordPress constant that enables displaying errors and warning messages.

How to enable WP_DEBUG:

  1. Connect to your server
    • Use an FTP client like FileZilla or the file manager in cPanel to access your WordPress files.
  2. Locate the wp-config.php file
    • The wp-config.php file is in the root directory of your WordPress installation.
  3. Download the wp-config.php file to your computer
    • Right-click the file and choose “Download”.
  4. Edit the wp-config.php file
    • Open the file with a text editor like Notepad++ or Visual Studio Code.
    • Find the line: define('WP_DEBUG', false);
    • If the line is missing, add the following lines before /* That's all, stop editing! Happy publishing. */:
      define('WP_DEBUG', true);
      define('WP_DEBUG_LOG', true);
      define('WP_DEBUG_DISPLAY', false);
    • This configuration:
      • Enables WP_DEBUG (true).
      • Stores errors in a log file (WP_DEBUG_LOG).
      • Hides errors from site visitors (WP_DEBUG_DISPLAY).
  5. Upload the wp-config.php file back to the server
    • After saving changes, use the FTP client to upload the file and overwrite the existing version.

2. Check the WP_DEBUG log file

  1. Find the debug.log file
    • The log file will be created automatically in the /wp-content/ directory if errors exist.
  2. Download and open the debug.log file
    • Check the file to identify the line, plugin, or theme causing the error. For example:
      [23-Jan-2025 15:00:00 UTC] PHP Fatal error: Uncaught Error: Call to undefined function example_function() in /path/to/wp-content/plugins/example-plugin/example.php:23
    • In this example, the problem comes from a file in the “example-plugin” plugin.

3. Deactivate problematic plugins/themes

  1. Connect to the server
    • Navigate to the /wp-content/plugins/ directory to access installed plugins.
  2. Rename the folder of the problematic plugin
    • If you identified a plugin causing the issue, rename its folder. For example, change example-plugin to example-plugin-deactivated.
  3. Test the site
    • Check if the site works after deactivating the plugin/theme. If the problem persists, repeat the steps for other plugins/themes.

4. Disable WP_DEBUG after resolving the issue

Once the problem is fixed, it is recommended to disable WP_DEBUG to prevent displaying error messages.

  1. Edit the wp-config.php file again
    • Change the line:
      define('WP_DEBUG', true);
      to:
      define('WP_DEBUG', false);
  2. Upload the file back to the server
    • Save and upload the wp-config.php file to the server.

Conclusion

With WP_DEBUG enabled, you can quickly identify the cause of critical errors in WordPress. While the process may seem daunting at first, following these steps will help you diagnose and resolve issues efficiently.