No other CMS provides that many options like WordPress does, and that makes it easier for everyone to experiment and make the customizations to whatever they want.
But customization doesn’t provide the expected results every time, and when it doesn’t it ends with some unexpected syntax errors.
So If you were trying something new on your WordPress site and got the following error message “Syntax error, unexpected…”, then don’t freak out. I keep receiving this message every next day, when I develop some WordPress themes in my studio & You are not the first one to receive the syntax error in WordPress, and you will not be the last one too.
In this article, I will show you how to fix the unexpected syntax error in WordPress.
Using Proper Syntax to Avoid Errors
Most of the syntax errors occur due to tiny errors that most people forget or don’t care about. Most of them are the comma, semicolon or a curly brace at the end.
Did you recently paste a snippet from the web? Updated a plugin? Then chances are you know exactly where to look.
Since most people are not developers and they copy codes from the internet and blogs and directly paste them in their files and mentioned in that blog.
So if you hit the Parse Error – Syntax error, Unexpected error in WordPress then here is what you can do.
- You can just delete or comment out the code you recently posted that resulted in a syntax error
- Find the error and fix it, Since most people are not developers and don’t know how to code, so this process may be the tough one
- The best way, visit your WordPress root folder and access your error_log in your cPanel. Analyse and read your WordPress error_log, since error log shows the exact problem that caused the error.
The 3rd option is the best way to know the problem, but the question is not just knowing about the problem, it’s about fixing the problem too. Most of the time when and user edit or paste some code they do it through the WordPress dashboard > editor and if they hit the syntax error then they are locked out of the WordPress dashboard.
So if in case you are locked out of the WordPress dashboard you can fix this problem using FTP.
Fixing the Syntax Error Using FTP
In order to fix the Syntax Error through FTP, you need to edit the code that caused this error. Often beginners freak out because this error causes your entire site to become inaccessible and you are locked out of your WordPress admin area.
After installing the FTP program, connect it to your website and go to the required file that needs editing (i.e: the file you were editing through your WordPress editor).
In case you forgot which file you need to edit, just look at the error_log or the error code. The error_log and error code 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 incorrect syntax or just comment it out. Once you are done removing/commenting/editing the code, save the file and upload it back to your server. Come to your WordPress site and refresh the page, and your site will be working.
We hope this article helped you fix Syntax Error in WordPress. Please leave your questions and feedback in the comments. I am always free and eager to help people.