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.
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.
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
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 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.
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.
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.
Syed Balkhi says
Hey WPBeginner readers,
Did you know you can win exciting prizes by commenting on WPBeginner?
Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
You can get more details about the contest from here.
Start sharing your thoughts below to stand a chance to win!
Roberta says
This is a frustrating error and your tutorial allowed me to fix it in less than 5 minutes. Thank you so much!
Jamie den Haan says
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,
Jamie
Aaron says
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.
WPBeginner Support says
Hi Aaron,
You can also connect to your server using File Manager app in your hosting account dashboard.
Admin
Daryl says
You’re amazing. Thank you for these videos.
Raffy says
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!
Kim martin says
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!
Micah says
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.
Tamia says
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!
WPBeginner Support says
Hi Tamia,
We are glad you found WPBeginner article helpful Don’t forget to follow us on Facebook for more WordPress tips and tutorials.
Admin
stanley says
Thanks for saving my website from errors
Tom Delano says
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.
WPBeginner Support says
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.
Admin
chris says
thank you so much! you saved me
Justine says
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
Giacomo Lawrance says
Thank you so much! You really saved me there. So grateful of this awesome site, thanks again!
Sara says
You saved my life!
Thank you so much!
Monica says
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.
Monica says
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:
shazwan says
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?
WPBeginner Support says
Hi shazwan,
Unfortunately there is no way around it. There are online tools that will help you figure out where you website is hosted.
Admin
Patrick says
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!
WPBeginner Support says
Hi Patrick,
Seems like upload was interrupted. Please try uploading the theme files again.
Admin