How to Display WordPress Error Messages Instead of “There Has Been a Critical Error on This Website”

How to Display WordPress Error Messages Instead of “There Has Been a Critical Error on This Website”

When managing a WordPress site, encountering the dreaded “There has been a critical error on this website” message can be frustrating and uninformative. This generic message does little to help you pinpoint the issue. Fortunately, WordPress offers a way to reveal the specific error messages that can guide you in resolving the problem.

In this guide, we will walk you through the steps to display detailed error messages on your WordPress site, discuss the security implications, and provide best practices for troubleshooting errors effectively.

Enabling Debug Mode in WordPress

To start displaying error messages, you’ll need to enable debug mode in your WordPress installation. This can be done by editing the wp-config.php file.

Step 1: Accessing the wp-config.php File

The wp-config.php file is located in the root directory of your WordPress installation. You can access this file using:

  • FTP Client: Use an FTP client like FileZilla to connect to your server.
  • File Manager in Hosting Control Panel: Most hosting providers offer a file manager in the control panel.
  • SSH: If you have SSH access, you can use the command line to navigate to the file.

Step 2: Editing the wp-config.php File

Once you have access to the file, you need to enable debugging by adding or modifying specific lines of code.

Adding Debugging Code

Locate the following line in the wp-config.php file:

define('WP_DEBUG', false);

Change false to true:

define('WP_DEBUG', true);

Next, ensure that error messages are displayed on the screen by adding these lines:

define('WP_DEBUG_DISPLAY', true);
@ini_set('display_errors', 1);

Step 3: Saving and Uploading the File

After making the changes, save the file and upload it back to the server. Your WordPress site is now configured to display detailed error messages.

Testing Your Changes

With debugging enabled, revisit your WordPress site. If an error occurs, the specific error message will now be displayed instead of the generic “There has been a critical error on this website” message. This detailed error information is crucial for diagnosing and fixing the problem.

Best Practices for Debugging

While displaying error messages can be immensely helpful, it also poses certain risks. Here are some best practices to follow:

1. Debug in a Staging Environment

Whenever possible, enable debugging in a staging or development environment rather than on your live site. This reduces the risk of exposing sensitive information to the public.

2. Revert Changes After Debugging

Once you’ve resolved the issue, it’s essential to turn off debugging by setting WP_DEBUG and WP_DEBUG_DISPLAY back to false. This prevents sensitive error messages from being displayed to visitors.

3. Monitor Error Logs

WordPress can also log errors to a file. This is useful for tracking issues without displaying errors on the page. Add the following line to your wp-config.php file:

define('WP_DEBUG_LOG', true);

This will create a debug.log file in the wp-content directory, where all errors will be logged.

Creating a Secure Debugging Workflow

To ensure that your debugging process doesn’t compromise your site’s security, consider implementing the following workflow:

1. Use Secure File Permissions

Ensure that your wp-config.php file has secure permissions to prevent unauthorized access. Typically, the file should have 644 permissions.

2. Backup Your Site

Before making any changes to your site, especially in the wp-config.php file, create a backup. This allows you to restore your site if anything goes wrong.

3. Regularly Update WordPress and Plugins

Outdated WordPress core files and plugins can lead to errors. Regular updates reduce the likelihood of encountering issues.

Common WordPress Errors and Their Solutions

Here are some common WordPress errors you might encounter, along with tips for resolving them:

Error Establishing a Database Connection

  • Cause: This error usually occurs when WordPress is unable to connect to the database.
  • Solution: Check your database credentials in the wp-config.php file. Ensure the database host, username, and password are correct.

White Screen of Death (WSOD)

  • Cause: The WSOD typically indicates a PHP error or memory limit issue.
  • Solution: Increase the PHP memory limit in wp-config.php or check for faulty plugins by deactivating them one by one.

Internal Server Error (500 Error)

  • Cause: This is a generic error that can be caused by corrupted .htaccess files, faulty plugins, or exhausted PHP memory.
  • Solution: Rename the .htaccess file and let WordPress generate a new one. Alternatively, increase the PHP memory limit or deactivate plugins to identify the culprit.

Key Takeaways

  • Enable Debugging: Use the wp-config.php file to enable debugging and display detailed error messages.
  • Security First: Always debug in a secure environment, and revert changes after troubleshooting.
  • Common Errors: Familiarize yourself with common WordPress errors and their solutions to resolve issues quickly.

Conclusion

Encountering errors on your WordPress site can be daunting, but with the right tools and knowledge, you can resolve them effectively. By enabling debugging and understanding common errors, you can troubleshoot problems swiftly and maintain a secure and functional website.

Remember to always disable debugging on live sites once the issue is resolved to protect your site from potential security risks. With these best practices, you’ll be well-equipped to handle any WordPress errors that come your way.

Talk with our Agent