Beginner's Guide for WordPress / Start your WordPress Blog in minutes

How to Fix the Syntax Error in WordPress

Are you wondering how to fix the syntax error in WordPress?

There are so many WordPress tutorials that require you to add code snippets to your website. Unfortunately, a small little error can cause the whole site to break which is very scary, especially for new users. If you were trying something new on your WordPress site and got the following error “Syntax error, unexpected…”, then don’t panic.

In this article, we will show you how to fix the unexpected syntax error in WordPress.

How to Fix the Syntax Error in WordPress

Using Proper Syntax to Avoid Errors

The first thing you need to do is to look at the beginner’s guide to pasting snippets from the web into WordPress. This article lists some very common mistakes made by beginners when pasting code in WordPress templates.

The syntax error is usually caused by a tiny but crucial mistake in your code syntax.

Example of a syntax error in WordPress

For example, it could be a missing comma or an extra curly bracket that can break the entire script.

Did you recently paste a snippet from the web? Updated a plugin? Then chances are you know exactly where to look.

Video Tutorial

Subscribe to WPBeginner

If you don’t like the video or need more instructions, then continue reading.

Fixing the Syntax Error Using FTP

In order to fix the syntax error, you need to edit the code that caused this error. You can either remove it or fix the syntax.

Often beginners panic because this error causes your entire site to become inaccessible. If you pasted the code using your WordPress dashboard Appearance » Editor section, then you are locked out. Check out our guide on what to do if you’re locked out of WordPress admin.

So how do you edit the code?

The only way to fix this is to access the file you last edited using FTP. Read our guide on how to use FTP for step by step instructions.

After installing the FTP program, connect it to your website and go to the theme file that needs editing. In case you forgot which file you need to edit, just look at the error code. The error will tell you exactly which file and which line you need to edit.

You can either remove the code you last added or write the code in the correct syntax. Once you are done removing or editing the code, save the file and upload it back to your server.

After that, visit your WordPress site, refresh the page, and you should see that your site is working again.

How to Prevent the Syntax Error in WordPress

In order to prevent your WordPress website from breaking again, we always recommend adding custom code with a code snippets plugin like WPCode.

WPCode plugin

WPCode makes it easy to add code snippets in WordPress without having to edit your theme’s functions.php file.

Plus, it comes with smart code snippet validation to help you prevent common code errors.

As you’re adding your custom code, WPCode will automatically detect any errors. Hovering over the error will bring up helpful instructions so that you can easily correct your mistake.

Smart code snippet validation to find code errors

WPCode will also immediately deactivate your custom code when it detects a syntax error.

Now, you never have to worry about breaking your site when adding code snippets.

Error handling in your custom code snippet

You can learn more in our guide on how to easily add custom code in WordPress.

We hope this article helped you fix the syntax error in WordPress. You may also want to see our ultimate guide to boosting WordPress speed, and our expert pick of the best code editors for Mac and Windows.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit – a collection of WordPress related products and resources that every professional should have!

Reader Interactions

85 CommentsLeave a Reply

  1. This is a frustrating error and your tutorial allowed me to fix it in less than 5 minutes. Thank you so much!

  2. Hi,

    Can someone please help me out? I keep getting a ‘SyntaxError: JSON Parse error: Unexpected identifier ”Error” when i want to check out on my website. I don’t know what to do and nobody can place an order!!

    Thanks a lot,


  3. I get “critical error: could not connect to server” when I enter my server information. So I can’t even get to the point that your video begins at.

  4. Thank you SO SO much! The bad snippet was invisible inside the Admin page in WordPress, for some reason, but fully visible in the functions.php found in the FTP!!

    You saved my day, thank you very much again!

  5. Thank you SO much! 7 days of getting My hosting service(a very large popular one) to try to fix this no luck just trying to upsell me on things I neither want nor need.

    Me thinking okay a whole new website and i found this, I just actually deleted the whole plugin(elementor) Whoo Hoo!

  6. Hello:

    I have run into this error helping someone else out with their website, so I wasn’t using my actual website when I got this error. I’m wondering how I can remove the error when I’m working on someone else’s site? I have their wordpress. org login information, but obviously I’m locked out of everything now. Any guidance would be appreciated.

  7. Thanks for this tutorial. I had a parsing/syntax problem when editing functions.php in a new website. I was working on the admin page of my WordPress site when I attempted to comment-out a line of code (using instructions by the theme author) but that caused the error. I had copied the functions.php code to TextWrangler, made the alteration, and pasted the whole doc back into the edit window. In “updating” the page I got the error and was effectively locked out of the site. So I used FTP to upload and overwrite the relevant doc, using a backup I’d made the previous day (thank goodness for those). If it hadn’t been for WP Beginner’s clear instructions here and on the “What To Do When You Are Locked Out of WordPress Admin (wp-admin)” post, I’d have been tearing my hair out. Thanks!

  8. In trying to log into my page via Filezilla, am I supposed to use my admin account or my WordPress account? I’ve tried both and the password authentication keeps failing. I have my original admin password and it’s worked consistently since I’ve had the website up.

    • Hey Tom,

      You’ll need to use your FTP username and password. You will find it in the email you received from your web hosting company when you first signed up. You can also find this information under your cPanel dashboard.


  9. I urgently need help. CO-editor on my site (which is supposed to launch tomorrow) tried to change code to change our profile pictures. Something went horribly wrong and we locked out of our site. Get this error: Parse error: syntax error, unexpected ‘add_filter’ (T_STRING) in

  10. Thank you so much! You really saved me there. So grateful of this awesome site, thanks again!

  11. Re: my last comment, I deactivated the plugin and the error went away. So you won’t see what I was describing anymore. I just decided to not use it than try to spend all night figuring out the problem.

  12. I am getting parse error syntax errors on all my product pages. This was brought to my attention by someone trying to shop my site. I have not made any edits to the code, installed any new plugins, or accessed the site at all in months. Not sure when this started but I haven’t had an order in few weeks. If I didn’t add or edit anything to cause this how do I know what to fix? All the error messages reference line 1 of the php file but all there is on line 1 is <?php. It's on all product pages. Here is just one example:

  13. Hi,

    I’m managing a website for my society and its has been long since the last time everyone actually had logged into the hosting account and we kind of lost the log in credentials and didn’t even know what hosting we’re using because they paid years ahead before. And maybe changed providers. But I know that our domain is from Godaddy and checked, but the hosting isn’t from the same provider.

    It may take some time as we dig through the emails, is there any way to fix syntax error other than through FTP?

  14. Hi. I tried uploading a theme though Filezila since WordPress was having issues trying to upload the theme and now I’m locked up and I get these two lines

    Please Help!!! Thank you!

Leave A Reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.