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.
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.