“There has been a critical error on your website”. While this message sounds cryptic, the idea behind it is to provide you with a single piece of information. If you came across it, there is definitely a critical error in WordPress. Let’s see how to override it quickly and restore the site, to a, at least, usable state.
Why do I get this error?
You may wonder, where does this message come from? WordPress creates this message to inform you that the front end of the website is broken. The good news is the WordPress Dashboard, in most cases, is still working. Hence, it’s a good idea to try logging in. If you are able to log in then you are already very close to resolving the problem. Actually, this is not a typical error message from the browser. It is an indication of the CMS is still in working condition.
The modern PHP challenges
But why can’t I see any other error messages? For security reasons, the platform will hide the actual messages. WordPress is mainly a PHP application. PHP has very detailed error messaging that informs about when something is going wrong. However, if those errors were allowed to display on the page it would provide technical information about your site to anyone visiting. It would also create a confusing experience for a random visitor who could easily hesitate to come back again.
Moreover, PHP also produces warning messages for the use of compliance with the latest programming directives. Even a new WordPress installation with a minimal theme installed may prompt one or more similar warning messages. After the speed-up of PHP development (back in 2020) that changed the release frequency of new packages, WordPress (and all related ecosystems) is running behind to catch up with the latest developments. For a short time, changing the PHP version became one of the top requests to the hosting companies. Today, new hosting packages come with the latest version of PHP (a strategy that boosted requests for downgrading to an earlier version, but this is another story).
Nevertheless, with the PHP messages hidden, the WordPress developers thought of this simple way to inform you when something is broken. This might happen for numerous reasons. For example, it can be as elementary as an open bracket or much more complex as a call to an unidentified variable. Put in place any other statement that doesn’t meet a condition. It could as well be a malicious attack. However, the message on the screen only lets you know that something is wrong, not what exactly is wrong.
Are you having trouble with your WordPress website? Did you know that Plethora Themes offer a great service that provide a seamless experience for you and your team? WatchPress is a complete WordPress technical management system that covers all your needs – so you can focus on what’s important. With a variety of available plans and scaling options, you can definately find what’s best for your personal blogging or business needs.
How to fix the critical error in WordPress
First thing make sure the problem is not related to a recent action of yours. A simple change (a line of code, a new plugin) could possibly create a conflict. However, we should never forget that a recent change may create an effect later unexpectedly. If you are not fun of (unpleasant) surprises, make sure you keep track of all changes, major or minor. When you are sure this is not a human mistake, proceed to troubleshoot.
Activate WP DEBUG
Hopefully, WordPress has integrated an overly detailed debugging system. It is not active by default, for the security reasons we mentioned before. To turn the WP DEBUG in WordPress you will need to access the physical files of the installation. To do so, you need to have (S)FTP access. If you are on shared hosting on one of the major and even smaller providers, the panel they offer includes a file manager that allows reviewing, editing, and manipulating the files of your site. That includes the WordPress core files as well.
According to WordPress documentation, activating WP DEBUG requires adding a few lines to the wp-config.php file that is located in the root folder of the installation. If you don’t feel comfortable directly editing this file, you can keep a backup. To do this, either download the file to your computer or create a local copy and rename it to something familiar. This way you won’t need to cry over spilled milk whatever happens.
To activate WP-debug edit the wp-config.php file and add the following lines:
// Enable WP_DEBUG mode
define( ‘WP_DEBUG’, true );
// Enable Debug logging to the /wp-content/debug.log file
define( ‘WP_DEBUG_LOG’, true );
This script, if you visit the site and try loading it again, will produce the debug.log file in the /wp-content/ directory. If it does not appear immediately you may need to “push the trigger” by trying to load the site a couple of more times. Eventually, it will come up.
Actively debugging in WordPress
At this point, you can download or review that file immediately (depending on the kind of file manipulation software you are using). It is a simple text file where all the errors are stored as simple lines. Even if you are not an experienced developer, if you investigate this file you may locate it in a few minutes. Here is what you need to do.
Debugging options
Check the location of the error. Typically, in the debug.log file, there should be a reference to the line of the error. Yet, this might not be the actual cause of the error rather than the location of a command that fails to run. By locating the line you should be able to find more evidence like a new reference to another line or file. Follow the references to the point you find the source of the error.
Supposing the error appears to be related to a plugin, try to deactivate it. If you have access to the Dashboard, just go to the Plugins and deactivate it. Else, use the file manager to delete or (better) move the plugin out of the /wp-content/plugins/ directory. In most cases, this action will bring up the site immediately! Note that, some functionality might be absent from the site after removing the plugin. In spite of that, the website will be running as expected and you can add a notice to the visitors about what is missing. This way you can buy some time until you resolve the issue permanently.
If the error appears to be located in a core WordPress file, you will need a few more steps to fix it. Locate the line of the error and check the references. You can try a web search with the error which will give you some extra ideas and, sometimes ready solutions. When it comes to WordPress, some errors become really popular from time to time. With a bit of luck, you can find a similar case by a person who managed to solve the problem.
If you suspect the website has been compromised but you still have access to the Dashboard, you can try a few more steps. One is to reinstall WordPress. You can do that with a simple click on the WordPress updates. Then, you can do the same with the plugins. Last, review the folders and make sure they don’t contain suspicious files.
Extra steps to fix a critical error in WordPress
If the above steps didn’t work, the problem is definitely more complex. There is also the (rare) chance you have run into multiple errors at the same time. At this point, we need to check the error messages thoroughly. For faster results, we can temporarily allow the debug errors to display on the screen. This will help you make some real-time changes to the files and review the results immediately. To activate the onscreen error report, add the following line to the wp-config.php file and save it as you did before.
// Disable display of errors and warnings
define( ‘WP_DEBUG_DISPLAY’, false );
@ini_set( ‘display_errors’, 0 );
This way all the errors that are recorded in the debug.log file, will also appear on the screen. It’s not the greatest thing to do and certainly, the experience for the user will be terrible at this time. But only for a short time, especially when there is a team working on the problem, is pretty useful as they can read the messages on the screen instead of scrapping the file into pieces. It will help them accelerate the troubleshooting.
Cleaning up after solving the critical error in WordPress
When you have located and solved the problem, and the site is up and running, don’t forget to deactivate the WP DEBUG. Leaving it active for a long time will put your site at risk. Moreover, the debug.log file will continue recording every single message and sooner or later will become huge and disk space is not free. To do so, remove the lines you’ve added to wp-config.php and save the file. Then, go to the /wp-content/ directory and remove the debug.log file.
Debugging your site in order to fix a critical error in WordPress is a relatively straightforward process. It only requires access to the files of the installation and critical thinking. Note that, you should always edit a PHP file with moderation as the language is sensitive to syntax mistakes. I strongly recommend keeping a full site backup (both files and the database) before proceeding, even if the site is down. This way you can have an untouched version of the site for further investigation in the future.
My name is Vangelis Chirmpilidis and I’m the author of this post. I am a long-term member of Plethora Themes as a Content Creator and Lead Customer Support Agent. I also contribute to the local WordPress community by participating in Polyglots, WordCamp, and other activities.
Add Comment