Isn’t it frustrating to see a Parse error: Syntax error message? You feel like you did everything right, but the results were not what you expected.
Getting a syntax error on your WordPress site is nothing to worry about: it’s one of the most common error devs encounter when building something on WordPress.
You don’t have to be discouraged just yet. Continue reading to discover how to fix the WordPress syntax error.
In this article, i’ll try to answer the most common asked questions about the Syntax Errors such as:
- What is parse error syntax error unexpected?
- How to Fix the Syntax Error in WordPress?
- How to Fix Parse error: syntax error, unexpected ‘ ‘ WordPress?
- How to Fix the Parse Error in WordPress?
- How to debug and fix WordPress Syntax Errors?
So let’s get started!
What is a Syntax Error?
Syntax errors occur when your code contains mistakes, so the compiler can’t parse the file and display your website.
The most common cause of syntax errors on WordPress is wrong code in PHP scripts.
Among the mistakes to avoid are missing punctuations, incorrect variables, and incorrect function names, etc.
In WordPress, there are typically three distinct types of parse errors that may affect a site:
- Syntax errors – They result from a misplaced semicolon, curly bracket, or quotation mark in the code.
- Unexpected errors – You might receive this error if you include characters, such as opening or closing brackets, or other similar characters. PHP encounters this error when it tries to locate something that is not found in the file.
- Undefined errors – This can happen when the character in an array that references a variable or possible scenarios is not correctly defined.
This is important to keep in mind that three different types of parsing errors refer to different scenarios, depending on the specific parsing error in the PHP code being written.
Fixing WordPress Syntax Errors
Step 1. Identifying The Corrupted File & The Error Line
To begin, let’s identify where the problem lies.
If the error appears after you just installed new plugins or themes, it’s highly likely that those are what’s causing the issue. You can deactivate them to fix the issue.
If your WordPress admin dashboard is not accessible and so can’t do that – keep reading. It’s also possible to troubleshoot the WordPress syntax errors with the error message.
From the error message, you can also trace the problem since it contains the full path to the corrupted file. Furthermore, it gives the line number of the corrupted code.
In this example, you know that the corrupted file is functions.php and that the php error is located somewhere close to line 91. The syntax error is therefore in this file, so in order to fix this, you should modify this file with your FTP client.
Step 2: Accessing The Corrupted File via FTP
Now that you’ve spotted the cause of the syntax error, it’s time to fix it:
- Open your favorite FTP client and head over to the containing folder of the file. In our example, the file can be accessed by navigating to public_html -> wp-content -> themes -> zerif-lite.
- Open the corrupted file (in our example functions.php) and locate the line (91) that causes the issue.
Step 3: Fixing The Syntax Errors
From here, you can edit the file directly with your FTP clients or download the file, edit-it with your HTML editor and upload it back.
To edit a file directly with Filezilla: click right on the file and then click on View/Edit.
FTP clients editor mode might sometime be hard to read. I personally prefer to download the file and open it with my HTML editor so I can have a better understanding of the syntax.
Add whatever is missing or incorrect (in this example the ” after “Hello World!) – save your file and upload it up.
The parse error should be fixed!
Final thoughts: keep learning about web development
The addition of code to your WordPress site is nothing to be ashamed about. Due to WordPress’ nature as an open-source platform, it is actually encouraged.
Yet you must be careful when making such changes because even the smallest error like forgetting to the bracket can be very problematic.
Do not let this slip deter you from working on your site ever again.