18 March, 2023
How to Fix a Syntax Error in WordPress

While using WordPress, when you edit the website, install plugins or add code snippets, have you ever been unlucky or careless and ended up with a syntax error? It can take the website down and leave it unreachable. If so, this article shows you how to fix a Syntax Error in WordPress.
What is a Syntax Error?
A Syntax Error is an error in WordPress that is usually called a syntax error. It is an unexpected error caused by a piece of code in some file. It usually appears when you leave out a piece of syntax or a statement, and updating a plugin can also cause it.
A Syntax Error also happens when you add code to a file in WordPress and the site can no longer be reached, showing messages such as “Syntax Error, unexpected…”. People who are new to building a website with WordPress run into this error often. Let's look at how to fix it below.
Ways to fix a Syntax Error
Fix a Syntax Error in WordPress with correct syntax
Common causes include a missing semicolon after a piece of code, a missing PHP closing tag in the file, or a missing closing bracket at the end of the code. First, read the error message carefully to see which file and which line it points to, so you can locate the error, then check the syntax in that file. Once you find the problem, correct it.
If you are not sure how to fix it, try to remember what you changed on the website so you can undo it. If it was a plugin, you can turn it off. If you cannot get in, you can disable the plugin by running chmod 000 on its folder.
See more:
- WordPress auto-posting plugin: an effective SEO tool for news websites
- What is Jetpack? What to know about the Jetpack WordPress plugin
- WordPress website security methods and plugins
Fix a Syntax Error through an FTP client
FTP is software that lets us access the source code of website a website using your hosting's FTP login. You can download and install FTP software such as WinSCP or FileZilla.
Open the website's source code with the file manager or FTP in hosting, check the faulty file and fix its syntax, or delete it. When there is an error, the whole site is usually unreachable, so you cannot edit the code in the theme editor in the WordPress Dashboard. You need to open it through FTP instead.
For example, I will fix the error shown in the picture above. Do you see that our error is in the file functions.php line 91.
Now use the path above to find the file functions.php.
Double-click the file when you see it to download it to your computer.
Find the error
A simple way to open a PHP file is with the default editor on your computer. But with a default editor it can be hard to find the exact error on a given line. So our advice is to use a dedicated code editor to edit the file, such as:
- Notepad++
- Sublime Text
- Atom
- Brackets
- TextWrangler
These tools number each line, as in the picture above, which helps you find the faulty line more easily and quickly.
Fix the error
If you are not used to editing and adding code, mistakes are unavoidable. What matters is understanding exactly what went wrong so you can fix it and stop it from happening again. Let's go through a few other reasons a Syntax Error shows up on your website.
Make sure you did not forget a semicolon or a closing bracket. These small mistakes are easy to spot, especially if you wrote those lines yourself.
If you paste code into the file yourself, make sure you paste it correctly and completely. Every PHP file starts with an opening tag <?php and ends with a closing tag ?>.
Some tutorials tell you to paste code at the end of the file. That can confuse beginners, who may paste it after the ?>. If you already pasted that code after the closing ?> tag, the simple fix is to copy that code and paste it before the ?> and you are done.
Also, if you added that line of code and cannot figure out the fix, simply delete it from the file.
Upload the file back to the website
As soon as you find the error and fix it, save the file. Then open FileZilla and upload the file back to its exact original path.
Fix a Syntax Error by uploading the original file again
Finally, if you cannot work out how to fix the code, try uploading a clean file. A clean file is an original file that has never been edited. If the problem is in the theme, download the theme from its provider and upload it to the website. Remember to delete the old, faulty version.
If the error is in the WordPress source code, download a copy from WordPress.org. Note that the WordPress version you download must match the version you are using.
Or you can download an older version by clicking All Releases to see all versions.
One thing to watch out for: if the problem is in the WordPress source code and sits in the wp-admin and wp-includesfolder, you can still upload these two again. But if it is in the wp-content folder, never upload that folder. Doing so can wipe out all of your website data.
So if the error is in the wp-content folder, you must track it down using the second method (FTP).
Conclusion
WordPress is open source, so editing or adding code to files is encouraged. Still, be careful with what you do, because one small mistake can cause real trouble, and nobody wants that. We hope this article helps you find the mistake and fix the problems around the error Syntax Error in WordPress.
FAQ
What is a Syntax Error in WordPress?
How do you fix a Syntax Error in WordPress with FTP?
Related articles
Professional website
design services
Own a website with a beautiful, 100% exclusive design and a lifetime warranty, with the ability
to expand features flexibly as your business grows, starting today!































Free AI courses
AI tools at work
VI
EN


