When you try to access your WordPress site, do you see an error page that reads “A critical error has occurred on your website”?
In this guide we will see how to quickly understand what is causing the WordPress critical error. This way you will be able to get your site back up and running as soon as possible.
What is “Your website has encountered a critical error” error?
The “Your website has encountered a critical error” alert is an error message that appears on WordPress sites.
When we try to connect to the backend of our site or even just visit it, all we see is a screen with this warning:
In some cases the error may appear only after certain actions. However, when it happens, it interrupts navigation on the site and also prevents us from accessing the administration area.
The notice may vary slightly and the text shown is one of the following:
There has been a critical error on your website. Please check your site admin email inbox for instructions.
What causes a WordPress critical error?
The problem “A critical error has occurred on your website” is also referred to as a “WordPress critical error” as it prevents access to the site and admin area.
The error can occur due to a problem with a plugin or a theme and basically always has a problem with a PHP script being interrupted.
Since this is one of the most common WordPress errors, the developers have introduced a feature that sends an email to help identify the cause of the error.
The email is sent to the WordPress site administrator’s address and contains the details of the error:
- type of error – for example a parse error (a type of PHP error);
- location of the error – the file and line of code where the error was found is indicated;
- error message – helps us understand the type of error, for example a syntax error in the code.
The problem is that this alert is not always sent via email.
Fortunately, however, the error can be identified quite easily. Let’s see how.
How to identify and fix “Your website has encountered a critical error”
To be able to resolve the “There was a critical error on your website” problem, you need to understand what caused the error.
To find the exact cause of the error you can do this:
- Method 1: Check the administrator’s email address to see if the email has arrived. Make sure you also check your junk mail folder.
- Method 2: Enable WordPress debug mode to see errors or check the server error log.
Both systems allow us to understand exactly the cause of the WordPress critical error. The second method is the one that allows us to resolve the WordPress critical error even if we have not received the email.
Let’s see how to activate debug mode and where to find the error log.
After locating the error, don’t forget to turn off debug mode. Simply reset the values of the rows we saw earlier to “false”.
In a production site (i.e. public and reachable by visitors) it is recommended to disable error display and debug mode.
Turn on WordPress debug mode
Even if we can’t access the back-end of our site, WordPress allows us to activate debug mode in a very simple way.
All we have to do is edit the WordPress configuration file. This is the file wp-config.phplocated in the root directory of your site. The directory can be called public_html or have the name corresponding to your domain.
If you have an active plan with SupportHost, for example a WordPress hosting plan, you can access site files directly from cPanel.
From the file manager you can search and find the file wp-config.php:
If you have multiple WordPress installations on the same web space, for example on subfolders or subdomains, make sure you are editing the right file.
With the file manager we can edit the file directly using the built-in editor.
Open the file wp-config.phpand locate the following lines:
define( 'WP_DEBUG', false ); define( 'WP_DEBUG_LOG', false );
We need to change the value to true, like this:
define( 'WP_DEBUG', true ); define( 'WP_DEBUG_LOG', true );
If they are not present, we just need to add them before the final line of the file, which shows this text:
/* That's all, stop editing! Happy blogging. */
Here I show you the result you must have:
By doing so we will have activated the debug mode and we will record the errors that are encountered.
The first line (WP_DEBUG) allows us to activate debug mode.
The second (WP_DEBUG_LOG) creates a new file
debug.log where errors are logged and stored.
You can also turn on the error display by adding this line:
define( 'WP_DEBUG_DISPLAY', true );
After editing the file, be sure to save your changes.
Now that debug mode is active you can also go check the file
debug.log inside the wp-content folder to see the error log.
Let’s see how to see the errors in both cases.
Identifying the error (screen display)
If you have turned on the error display (with the WP_DEBUG_DISPLAY variable), just visit the website’s home page and you’ll see the error, like in our example below:
Now we just have to interpret the error, let’s see how to do with the case of our example.
The notice states:
- the type of error, in our case a parse error;
- the file concerned and the path in which to find it, in our example ” post.php”;
- the line where the error occurs, line 72.
Keep in mind that there can be multiple errors, like in our case where there are two errors of the type “notice”. In this specific situation, however, the problem causing the WordPress critical error was only the first one: a syntax error in the file.
Check the debug.log file to locate the error
If you haven’t activated the WP_DEBUG_DISPLAY feature, you can check the error directly by consulting the
The file is located inside the wp-content folder, as you see here:
In our case the error we just saw was logged, and the file
debug.log will have this content:
Exactly as we have seen before, the type of error, the file in which it occurred and the corresponding line of code are reported.
Check the error_log file
Generally turning WordPress debug mode on is enough to identify the error and fix the WordPress critical error issue.
Anyway to check for any PHP errors, you can also check the .error_log
If you have a hosting plan with SupportHost, then this file is automatically generated and you can find it in the error directory.
Just check your site’s public_html folder and open the file to read the errors.
You can also simply do a file search via cPanel’s file manager, like this:
WordPress critical error: solutions to the most common causes
To identify what caused the “Your website has encountered a critical error” warning to appear, the best solution is to follow the two methods we have just seen.
In doing so we can trace the error precisely and can solve it.
Below, however, we list some of the most common causes that could have generated the problem and see what the solutions are:
|Conflict with plugins||Deactivate plugins|
|Problem with the theme in use||Reset the theme to default|
|Outdated PHP version||Change the PHP version|
|Insufficient PHP memory limit||Increase the PHP memory limit|
|Can’t determine the cause||Restore a WordPress backup|
Let’s take a look at the possible solutions to the problem “A critical error has occurred on your website” one by one.
One of the causes of WordPress critical error is plugin issues. In this case, disabling all installed plugins and re-enabling them one by one may solve the problem.
Since the error does not allow us to access the backend, we have to deactivate the plugins manually.
To do this we follow these steps:
- access site files via file manager or an FTP client such as FileZilla or Cyberduck;
- rename the “plugins” folder to “plugins-deactivated“.
Then you will need to create a new “plugins” folder and move the individual plugin folders one at a time to figure out which one is causing the error.
Alternatively you can deactivate the plugins from the database, following the procedure we have explained here: deactivate plugins with phpMyAdmin.
Restore the default theme
Sometimes even WordPress themes can have conflicts causing the critical error. We can change the WordPress theme in use even without having access to the dashboard.
To do this we need to access the database using phpMyAdmin and change these values in the wp_options table:
In the option_value column, let’s insert the name of the theme we want to use, as I show you here:
If you are not familiar with the database, check out the step-by-step procedure in our guide on how to use phpMyAdmin for WordPress to perform database operations.
Change the PHP version
In some cases, if you see the message “A critical error has occurred on your website” on your site, the cause may be the PHP version you are using.
If you’re using an outdated PHP version, you should upgrade to a newer one and see if that fixes the problem.
With SupportHost you can independently set the version you prefer to use, just follow our tutorial on how to change the PHP version from cPanel.
Increase the PHP memory limit
What if the problem is a memory limit? Too low a limit can break the execution of a PHP script.
There are several ways to change this threshold.
SupportHost allows you to change the memory limit directly from cPanel’s PHP Selector tool, like this:
- open the options tab;
- change the value to match “memory_limit”.
On this screen I have highlighted the value to be changed.
Alternatively you can change the memory limit by adding this line in the file wp-config.php:
define( 'WP_MEMORY_LIMIT', '128M' );
Restore a WordPress backup
In our WordPress backup guide, we talked about the usefulness of always having an updated copy of your site files in case of errors.
When all the previous solutions have not worked and your site is still unreachable due to the message “A critical error has occurred on your website”, you can still run for cover. Just restore a recent backup.
In the guide linked above we have explained step by step how to do it.
If you have not been able to trace the causes of the error, it is also advisable to scan the site to rule out the presence of malware that has compromised the files.
SupportHost offers you two tools to scan your site for viruses: ClamAV and Imunify360.
The “A critical error has occurred on your website” alert can be frightening for WordPress site administrators who suddenly find themselves unable to log in to the site.
Luckily, however, WordPress has a debug mode designed to help users find errors and be able to fix them.
You just need to know where to look.
We’ve covered how to identify the problem causing the WordPress critical error and also listed the most common causes and solutions.
And you, were you able to figure out what was causing the error on your site? Let us know with a comment.