How to Solve “Parse Error: Syntax Error, Unexpected” and Fix Syntax Problems on WordPress
Isn’t it disheartening to see a Parse error: Syntax error message? You feel like you’ve done everything correctly, but the results are not as expected. Well, don’t be discouraged just yet. Read on to find out how to fix the syntax error on WordPress.
What is a Syntax Error?
A syntax error occurs when there’s a mistake in your code. As a result, the compiler cannot process (parse) the file and fail to display your website.
On WordPress, syntax errors are usually caused by incorrect lines in PHP scripts. Some common mistakes are incorrect coding structure, missing punctuations, invalid variables, and wrong function names.
Fixing WordPress Syntax Errors
Here are the steps to fix syntax errors on WordPress:
1. Determining the Corrupted File
Let’s begin by recognizing the source of the problem.
If the error appears after you’ve just installed new plugins or themes, there’s a high chance that they’re the ones causing the issue.
Alternatively, it’s also possible to trace the root of the problem from the error message because it contains the full path of the corrupted file. Furthermore, it mentions the line of the faulty code as well.
Let’s take a look at the following syntax error message:
We can see that the error is caused by the 73rd line of the index.php file. As such, this is the file you need to modify to fix the syntax error.
If your site shows a white blank page with no error message, enable the debug function or activate the display_errors feature by accessing hPanel -> PHP Configurations -> PHP Options. Then, you’ll see the message after you reload your site.
2. Fixing the File from the File Manager
Now that you’ve spotted the cause of the syntax error, it’s time to fix it:
- Open hPanel’s File Manager and head over to the containing folder of the file. In this case, the folder can be accessed by navigating to public_html -> wp-content -> themes -> twentyseventeen.
- Double-click on the corrupted file and locate the line that causes the issue. From the example above, we’re going to open the index.php file and edit the 72nd line.
We can see that a very important part is missing — a semicolon to end the get_footer function.
- Place the semicolon on the 72nd line.
<?php get_footer() ;
- Hit Save & Close and reload your site.
In some cases, removing the line can also fix syntax errors. For instance, there is a comment that is missing escape characters and is thus being interpreted as code. Deleting this line will fix the error.
However, be careful if you want to delete a line as it may trigger another problem. A line that’s responsible for computing a variable’s value, for example, cannot be deleted because it is used later lines.
Encountering syntax errors may be frustrating as your WordPress site will not show its actual content.
However, fixing syntax errors is pretty easy. All you have to do is determine the corrupted file and modify it from the File Manager.
Follow our tutorial above, and your site will work properly in no time! Good luck!
Learn How to Solve Other WordPress Errors
How to Solve “There’s Been a Critical Error on Your Website” Error
How to Fix Database Connection Errors on WordPress
How to Solve Internal Server Error (500) on WordPress
How to Fix upload_max_filesize Errors in WordPress
How to Solve max_execution_time Exceeded Error
How to Fix Broken Permalinks in WordPress