How to Fix Syntax Errors in WordPress
Yes, there’s a problem, but it’s possible to fix it.
Your site hasn’t disappeared into the ether. It’s still there, behind that error message. The issue may be something as simple as a missing semicolon in a PHP file. WordPress syntax errors aren’t frequent, but they do occur and are relatively simple to correct.
In this article, we’ll explain what a syntax error is, along with some common causes. Then we’ll walk you through the steps to take to locate and fix the error. Let’s get started!
What Is a Syntax Error?
A syntax error occurs when a command is not written correctly.
This may include the presence of a grammatical mistake, a misspelled word or missing symbol, or an incorrect punctuation mark in your site’s code. In WordPress, this is usually a PHP error.
Skip the Stress
Avoid troubleshooting when you sign up for DreamPress. Our friendly WordPress experts are available 24/7 to help solve website problems — big or small.
Common Causes of Syntax Errors in WordPress
A syntax error may occur when you’ve pasted code incorrectly. Maybe you missed a portion when you copied the code or perhaps there is an extra closing tag at the end of the script.
This is a PHP open tag: <?php, and this is a closing tag: ?>.
When you copy and paste a PHP code snippet, it often includes the open tag, causing a syntax error. Since you are probably pasting the snippet into existing code, you don’t need to include the open tag.
You may also get a syntax error when you are editing your theme in the WordPress Customizer. If this happens, you’ll generally know what the problem is, or at least where in the file it’s occurring. If you aren’t sure, don’t worry. You can locate the error by making a few changes to the wp-config.php file.
Another reason you might see this message is because of a plugin update or installation. The extension may not be compatible with your WordPress version, or there may be other issues at play. If you were updating or installing a plugin when the error happened, that’s most likely the source of the problem.
Why Fixing the WordPress Syntax Error Matters
A syntax error is an indication that something isn’t right within your site’s code. This issue can break your website, leaving you with a blank page or error message.
If your website is down or inaccessible, it will obviously hamper the User Experience (UX). Besides hurting your traffic and conversion rates, having a blank page where your site should be can also hurt your Search Engine Optimization (SEO) rankings.
WordPress syntax error messages can be concerning, especially if you aren’t familiar with website code. Fortunately, as you’ll see, most syntax errors have a simple solution.
How to Fix a Syntax Error in WordPress via SFTP
When a syntax error occurs, you can fix it by either removing or correcting the code containing the error. Either way, you’ll need access to the file where the problem is occurring. If you’re locked out of your WordPress admin dashboard, you can access this by using a File Transfer Protocol (FTP) client.
If you’re a DreamHost customer, this process is especially easy. There’s no need to download a third-party application. You can access your website files using our dedicated WebFTP tool.
If you aren’t a DreamHost customer or prefer to use an FTP client, FileZilla is a good option. Note that you’ll always want to connect using the more secure Secure File Transfer Protocol (SFTP) rather than FTP. This will ensure the transferred data is encrypted.
You will need some information to connect to your website via SFTP:
You can find this information by logging into your web hosting account. DreamHost users can navigate to Manage Account. If you’re using another hosting provider, they may call this area something different — if you need help, contact your host or visit their knowledge base.
From the account management area, look for FTP Users (or FTP Accounts, depending on your web host) and select Manage Users to view your Host, Username, and Port settings. If you don’t know your FTP password, you can reset it with the link provided.
Next, open your FTP client and enter your login credentials. Once logged in, under your WordPress site’s directory, you will see the wp-admin, wp-content, and wp-includes folders, and a list of other files.
If your screen looks similar to the above example, you’re in the right place! Now, it’s time to enable debugging to get more information about the syntax error.
Enable Debugging to View the Syntax Error Location
If you were working on your website when the error occurred, you should have a good idea of where to look for the issue. However, if you’re unsure, there’s no need to guess. Debugging will show you the exact location of the error.
To enable debugging, you can add the following snippet of code to your wp-config.php file:
define( 'WP_DEBUG', true );
Be sure to put the code before /* That’s all, stop editing! Happy blogging. */ toward the bottom of the file.
Once you save the file and refresh your website in your browser, you should see a text string indicating the location of the error, including the file, name, and line number.
Be sure to disable debugging once you’ve fixed the syntax errors, as leaving this feature on isn’t recommended for live websites.
You’ve now located the syntax error. After noting the information, it’s time to get to work fixing it. You can use the directions below to address the error according to its location.
Fix a Syntax Error Caused By a Plugin Update
If you were installing, updating, or editing a plugin file when the syntax error occurred, the simplest and fastest solution is to disable the plugin. That’s what we’ll do first.
Access your website via SFTP. Once you’re connected, go to the wp-content/plugins directory, and locate the plugin folder with the error.
While there, you can either disable the plugin or correct the file that contains the error — if you know what’s causing the issue. If not, you can disable the plugin by renaming its folder in the plugins directory.
If you go to your website’s URL and refresh the browser, your site should appear normal. However, if you want to continue using the plugin, you’ll need to resolve the error rather than simply disabling it.
To correct the plugin error, locate the file and line number from the error message. Identify any missing or incorrect code on that line. If you’re unsure what’s causing the error, you can paste the snippet into a code editor to help you identify it.
You can always disable the plugin as a short-term fix. Then, you can reactivate it later, once the error is corrected. This may be the best approach, especially if the plugin isn’t essential to your website’s operation.
Fix Syntax Error Caused By Editing a Theme File Improperly
To fix an error that occurred while editing your theme, access your website via SFTP, and navigate to the wp-content/themes folder. Open the appropriate theme folder and locate the file with the error — usually the functions.php file.
Edit the file and correct the error. Again, the syntax error code should display the line number. If the problem occurred when you pasted a code snippet into the file, delete your edits to restore the file to its stable version.
If you don’t see what’s causing the problem, you can use a code editor to help identify the error. Once you correct the problem, open a browser window, and navigate to your URL to verify that your site is up and running again.
Use a Code Editor to Identify Syntax Errors
In the illustration below, the functions.php file is missing a semicolon on the last line.
The editor indicates the syntax error with a yellow bar beside the line number (610). Once we add the semicolon, the error resolves, and the yellow flag disappears. You can practice writing or editing code in an editor before making changes to your website’s files.
How to Avoid Syntax Errors in the Future
Using proper syntax can help you avoid errors in the future. PHP is a simple, flexible language. You can invest a little time to learn the basics. Then, when you’re pasting code or making edits to your site’s files, you’ll know how to correct errors as you work.
As another option, you can keep a code editor handy to check syntax before pasting code into your website. This is a smart practice for ensuring that a code snippet is correct before adding it to files on a live site.
Another way to prevent issues is to enable debugging when making changes to your site, in order to flag errors before going live. This is the time to make sure everything is compatible with your WordPress core files and works as it should.
Finally, we suggest deleting any unused plugins and themes. Not only can this help prevent syntax errors, but it is also a good security measure, so it’s a win-win.
Get Content Delivered Straight to Your Inbox
Subscribe to our blog and receive great content just like this delivered straight to your inbox.
Other WordPress Error Tutorials
Want to learn everything there is to know about common WordPress errors? We’ve put together several guides to help you troubleshoot potential issues.
- How to Fix the 500 Internal Server Error in WordPress
- How to Fix the WordPress Not Sending Email Issue
- How to Fix the Error Establishing Database Connection in WordPress
- How to Fix WordPress Error 404 Not Found
- How to Fix the Sidebar Below Content Error in WordPress
Ready to Fix That Syntax Error?
In this article, we explained what syntax errors are and their most common causes. Then we provided a step-by-step guide for fixing syntax errors in your WordPress installation. These are usually simple to resolve, but it’s best to take measures to prevent the problems from appearing in the first place, such as using a code editor to check code before adding it to your site.
Properly maintaining your website is one of the best ways to avoid issues and keep it running smoothly. DreamPress hosting (with free WordPress migration) is specifically designed for the WordPress environment. Plus, if you ever do encounter a problem, we’ve got you covered with automatic daily backups and a support team of WordPress experts!