You’ve probably heard the phrase: WordPress Syntax Error. This is the dreaded white screen with an error that says something like “Parse error: syntax error, unexpected…” This is a common error when things go wrong with WordPress. Fortunately it’s not (usually) a difficult error to fix. Let’s take a look at the most common causes and how to troubleshoot it to get your website back up and running as quickly as possible.
Why the WordPress Syntax Error Happens
Typically, this happens because a snippet of code is placed within a theme file incorrectly or the code itself contains an error like a character or a tag in the wrong place or it’s missing altogether.
The Internet is filled with code snippets, plugins, themes, and tutorials about WordPress that promise to add new features that we want or that teach us about programming code for WordPress. Sometimes these tutorials and code snippets have errors. Sometimes we add our own errors through typos or through trying to make modifications (guilty!). One simple error is enough to bring a WordPress site down. I’ve done it more than once and unless you troubleshoot the problem correctly, it can take hours to isolate the issue and fix it.
In the case pictured above, I created this error by deleting a closing parenthesis ) on line 35 in the functions.php file for the Twenty Sixteen theme. I simply went to the editor, opened the file, deleted the parenthesis, and saved it. It was that easy to bring my site down.
Fortunately, the error itself tells me where the problem is. Now all I need to do is get access to the functions.php file and fix it.
Fixing It with FTP
It can sometimes be impossible to get back into your website once you’ve had this error. In this case, you’ll have to access it a different way. You can use an FTP app to access your website’s folders and make changes. There are lots of good FTP programs available. I’ve used FileZilla many times with great success. It’s free under the GNU license and works with many platforms. Some hosts provide FTP within cPanel. But they all work the same way by giving you access to the files and folders on your server.
Log in to your server with your FTP app, navigate to your theme’s folder, and find the file that has the error (this information is given within the error on your website). First, you’ll need to download the file.
To find your theme file using your FTP app go to wp-content > themes > name of theme > name of file.
Select and download the file and then open it (or view and edit, depending on your app) to make the changes. When you’re done, save your changes and upload the file to your server (replacing the original). Once you’ve uploaded the file, you can refresh your website and it should be working.
If you don’t want to troubleshoot the code and the problem happened after installing a theme or plugin you can navigate to it and delete it. I’ve had to do that a few times. This can sometimes make your site behave abnormally though until you get back in and clean it up. Proceed with caution anytime you’re deleting something.
Troubleshooting the Error
First and foremost – remain calm. Your website isn’t damaged beyond repair. These errors are common enough that practically everyone who works with WordPress has seen it or will see it eventually. You’re not alone and panicking won’t help you. Follow a few methodical troubleshooting steps and your site will be back up and running in no time.
Errors are usually caused by missing commas, placing code on the wrong side of a curly bracket, or even placing the code within the wrong file. I’ve done all of these myself and it’s extremely easy to do.
In my example above, I’m opening the functions.php file and replacing the missing parenthesis. Fortunately I already know what the problem is, but what if you need to troubleshoot the code to find the error?
If you’re not sure where the problem is you can copy and paste the code into an IDE (interactive development environment) or code editor. Once I’ve fixed the problem I can save it and my site will be running again. Fortunately these tools are easy to find and use.
There are lots of good tools to help you debug code. Here is a quick look at a few online tools that are free to use. This is a great way to troubleshoot the code if you’re not sure what the error is. Some of the tools will highlight missing elements (such as a missing bracket) and others will let you step through the code to see how it works. All of them will run the code so you can see the results.
Cloud 9 is an online IDE with 150 different code languages. It has a built-in debugger that lets you set breakpoints, step over, step through, execute code, and even set it in any browser. You can use the free account or get a pro account starting at $19 per month. If you’re serious about coding, this is a tool to consider.
In order to see a list of errors that your website has experienced you can place your WordPress installation in debug mode. This is done with code in your wp-config.php file. You’ll need to either add the code or activate the code if it already exists. If the code exists then switch the true/false Boolean values.
If your site is a local installation you can to turn on debug mode in order to troubleshoot the problem. This will display a list of your sites errors on the main page, so this is best used on a local installation rather than on a live site.
Go to your wp-config.php file and look for a line that says:
“That’s all, stop editing! Happy blogging.”
Above this line add this line of code:
define( 'WP_DEBUG', true );
If the code is already there just set it to true.
Use this code in the same place for a live site:
// Enable WP_DEBUG mode define('WP_DEBUG', true); // Enable Debug logging to the /wp-content/debug.log file define('WP_DEBUG_LOG', true); // Disable display of errors and warnings define('WP_DEBUG_DISPLAY', false); @ini_set('display_errors',0); // Use dev versions of core JS and CSS files (only needed if you are modifying these core files) define('SCRIPT_DEBUG', true);
Troubleshooting Using Plugins
Sometimes instead of seeing a PHP error with a number telling you which line contains the error you just get a blank screen. This can make it more difficult to figure out where the errors are coming from. For these cases you’ll need a little more help. If you to have access to the dashboard then you can troubleshoot using plugins. These are the most popular debugging plugins for WordPress.
Debug Bar adds a menu to your admin bar that shows debugging information. It tracks SQL queries, PHP warnings, notices, shows cache, etc.
Debug This adds a debug menu to the admin bar that has 49 debug modes. It will debug code menus, images, widgets, sidebars, PHP, cache, cron, attachments, and lots more. It has an API where you can create your own debug modes if it doesn’t have what you need.
Debug helps you find errors by editing the wp-config.php file so you don’t have to handle the debug mode code manually. It enables error reporting and will send you email notifications on runtime bugs. It will create an error log, display errors, and enable script debug save queries.
Turn Off Themes and Plugins
Another way to help you troubleshoot, if you can get back into your dashboard, is to disable or delete any new themes and plugins that you’ve installed. Sometimes a problem can occur when there’s a conflict between plugins or themes. Turn them back on one at a time until you find the culprit. I like to open the site in another window so I still have access to the dashboard. Refresh the window for the site and continue until you’ve found the problem.
If you’re using a caching plugin then try clearing your site’s cache. You’ll do this manually through the plugin’s settings.
Tips for Avoiding Errors
- Always make a backup before trying code on your website. This way if you do have an error you can get your site back to running quickly.
- Test the code first. There are several places online where you can test code or you can try it out in a test server before placing it into your live WordPress site.
- Be careful how you paste the code. One small error is all it takes to bring your website down and it’s easy to place the code in the wrong location.
- For themes and plugins look at when it was updated and read the reviews and support to see if there are any recent issues.
- Check to ensure you haven’t exceeded your bandwidth limit. If you have then your host might have blocked your site.
If you ever do come face to face with a WordPress syntax error just know that you’re not alone and it’s not that difficult to fix. By using a few simple tools and doing some methodical troubleshooting you can get your website back up and running in no time.
Article thumbnail image by Pro_Vector / Shutterstock.com