Syntax errors in WordPress can feel overwhelming, especially if you’re new to coding.
You might encounter this issue when adding code snippets from tutorials. Even a tiny mistake can break your entire site.
If you’ve seen the dreaded “Syntax error, unexpected…” message, there’s no need to panic – you’ve come to the right place! We have run into and fixed this error a bunch of times on our websites, and we know how to help you solve it.
This guide will walk you through the steps to fix the syntax error in WordPress. By the end, you’ll know how to get your website back up and running smoothly.
What Is Syntax Error in WordPress and Why Should I Care?
A syntax error in WordPress occurs when the code you’ve added has incorrect syntax, meaning it doesn’t follow the rules of the programming language.
This kind of error can happen from something as simple as a missing comma, an extra bracket, or a misplaced quotation mark.
So why should you care about syntax errors?
First, they can bring your entire website to a halt. Instead of seeing your beautifully crafted site, visitors are greeted with an error message. This not only affects the user experience but can also harm your website’s reputation and reliability.
Additionally, syntax errors can make it impossible for you to access your WordPress admin area. This can be particularly stressful if you’re uncomfortable with coding and don’t know how to fix the issue.
In short, syntax errors are small but significant mistakes in your code that can have a big impact on your website. Being able to identify and fix these errors quickly is key to maintaining a smooth and professional-looking site.
Using Proper Syntax to Avoid Errors
Ensuring your code is correctly written from the start can save you a lot of headaches. By paying attention to proper syntax, you can avoid many common pitfalls that lead to errors.
The first thing you need to do is look at the beginner’s guide to pasting snippets from the web into WordPress. This article lists some common mistakes beginners make when pasting code in WordPress templates.
The syntax error is usually caused by a tiny but crucial mistake in your code syntax. For example, a missing comma or an extra curly bracket 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 prefer written instructions, keep on reading.
Fixing the Syntax Error Using FTP
To fix the syntax error, you need to edit the code that caused it. You can either remove it or fix the syntax.
Often, beginners panic because this error makes their entire site inaccessible.
If you pasted the code using your WordPress dashboard’s Appearance » Editor section, then you are locked out. You can 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. For step-by-step instructions, you can refer to our guide on how to use FTP.
After installing the FTP program, you’ll want to connect it to your website and go to the theme file that needs editing. If you forgot which file you need to edit, simply look at the error code. The error will tell you exactly which file and line you need to edit.
You can either remove the code you last added or write the code using the correct syntax. Once you are done removing or editing the code, save the file and upload it back to your server.
After that, you can visit your WordPress site and refresh the page. You should see that your site is working again.
How to Prevent the Syntax Error in WordPress
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. It also comes with smart code snippet validation to help prevent errors.
As you add your custom code, WPCode will automatically detect any errors. Hovering over an 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.
With this plugin, 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.
Is your WordPress site broken? Don’t panic – our Emergency WordPress Support team can help. Our on-demand service can get your website back online fast, ensuring minimal downtime. No ongoing contracts, just one-time solutions. Schedule a call now!
We hope this article helped you fix the syntax error in WordPress. You may also want to see our guide on how to fix the WordPress updating failed / publishing failed error or our list of common WordPress block editor problems and how to fix them.
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.
Roberta
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
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
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
Hi Aaron,
You can also connect to your server using File Manager app in your hosting account dashboard.
Admin
Daryl
You’re amazing. Thank you for these videos.
Raffy
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
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
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
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
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
Thanks for saving my website from errors
Tom Delano
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
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
thank you so much! you saved me
Justine
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
Thank you so much! You really saved me there. So grateful of this awesome site, thanks again!
Sara
You saved my life!
Thank you so much!
Monica
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
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
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
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
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
Hi Patrick,
Seems like upload was interrupted. Please try uploading the theme files again.
Admin