When you are dealing with a syntax error in WordPress, by default WordPress won’t reveal the error directly on your website, but instead it will suggest that “There has been a critical error on this website”.
Fixing these is pretty easy if you know what you’re looking for.
How To Fix A Syntax Error in WordPress
The first step would be to find out what’s causing the error for your website. For this you will have to enable debugging mode for your WordPress website.
You can easily do this this from your site’s configuration file also know as
wp-config.php file, that’s located in the directory where your website has been installed.
If you are using cPanel, you can easily edit the file using the online File Manager feature. If you are not using cPanel, then you can connect to your hosting account using an FTP client.
The next step is to edit the
wp-config.php file and look for the following line of code:
define( 'WP_DEBUG', false );
In order to temporarily enable debugging mode for your website, you’ll have to set ‘WP_DEBUG’ to true instead of false. So the line of code would look like:
define( 'WP_DEBUG', true );
Now that the debugging mode has been enabled, you can return to your website and try to access it again. You will notice that instead of showing that “There has been a critical error on this website” generic error, it will reveal the actual error that’s causing troubles to our website. Like the one below, which is related to our case.
So as you can see, in our case the website complains about a syntax error on the theme’s functions.php file which is located in wp-content/themes/twentytwentyone directory.
Find the file which is giving you a Syntax Error. If you review the error message you receive, you will see the directory path and file name causing the error, as well as the line on which the error occurs.
The next step is to connect to FTP to your hosting account. After you open the theme folder, look for the file. In our case, it’s functions.php.
If you are using File Manager in cPanel, it has an integrated HTML Editor which you can access by right clicking the functions.php file (or the file causing the error in your particular case) and choosing Edit.
A new tab in your browser will spawn and you will see the codebase that outlines the structure of this themes functions.php file. Don’t worry if this seems overwhelming, we’re only looking for the correspondent line indicated in your error.
If you find it difficult to figure out what’s causing the syntax error, you can try using a syntax validator online tool. Once you’ll manage to fix the syntax error you should save the changes.
Now, open a new tab in your browser and try to load your website. If it works, great! You solved your issue! Congrats! ✋🎉
The final step is to edit the
wp-config.php file and to disable debugging mode for your website:
define( 'WP_DEBUG', false );
If the steps above didn’t solve your issue, you might need to restore the website files from a backup if you have one available.
If you’re a ChemiCloud customer, you can rest easy! All our WordPress hosting plans come with 30 day daily offsite backups allowing to be quickly restored.