18 March, 2023

How to Fix a Syntax Error in WordPress

Quick summary: There are three main ways to fix a Syntax Error in WordPress. First, read the error message to find the file and line, then fix the syntax (check semicolons, closing brackets and PHP tags). Second, use an FTP client such as FileZilla to download the faulty file, open it in a code editor such as Notepad++ or Sublime Text to find and fix the error, then upload it again. Third, download a clean original file from the theme provider or from WordPress.org to replace the faulty file.

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.

syntax error

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:

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.

syntax error

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?
A Syntax Error in WordPress happens when a piece of code in a PHP file is missing syntax such as a semicolon, a closing bracket or a PHP tag. The website then cannot be reached and shows an error message like 'Syntax Error, unexpected…'.
How do you fix a Syntax Error in WordPress with FTP?
Use FTP software such as FileZilla to connect to your hosting. Find the faulty file from the path in the error message, download it, open it in Notepad++ or Sublime Text to find the faulty line and fix the syntax, then upload it back to the original path.
About The MONA Group: Founded in 2016, with 60+ staff, MONA has delivered 14,000+ projects with an 85% client retention rate. MONA provides website design, full-scope SEO, custom software and AI automation solutions for businesses. Consultation hotline: 1900 636 648. Explore MONA AI Agent suite and MONA SEO services.
MONA has a podcast: listen instead of readingEpisodes on AI, automation & SEO for Vietnamese businesses
Nghe ngay
About the author

CEO & Founder · The MONA

The founder of The MONA built a service company of 60+ staff with 14,000+ projects delivered. Khánh Hùng shares his thinking on building self-running systems, automating a business, and the real lessons behind MONA's projects.

Views 1,5K
Rate this article 4,6/5 · 13 ratings

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!

Contact Mona

    MONA có riêng một Người "Bạn Thân" cho bạn - Người Account sẽ đồng hành, hỗ trợ, hướng dẫn, đặt đồ ăn cho bạn mãi mãi, từ đây về sau!
    MONA will never sell your information or send you spam
    Đội MONA tư vấn hệ thống quản lý giáo dục trực tuyến
    Hỏi đáp giáo dục 4.0
    Tạo cuộc hẹn miễn phí với MONA để giải đáp và tư vấn mọi thắc mắc về giải pháp số hoá ngành giáo dục
    Thời lượng cuộc hẹn
    45 Phút
    Ngày và giờ
    Thứ 2, ngày 25 tháng 12, 2023
    [9:30 - 10:15]

      Chọn ngày và giờ
      Khung giờ
      Back
      Hãy cho MONA biết bạn là ai
      0:00