How to Solve “Parse Error: Syntax Error, Unexpected” and Fix Syntax Problems on WordPress

[ad_1]

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 punctuation, 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:

A syntax error message that appears on the homepage.

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.

Pro Tip

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:

  1. 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.
  2. 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.
How to locate the syntax error in index.php file.

We can see that a very important part is missing — a semicolon to end the get_footer function.

  1. Place the semicolon on the 72nd line.
<?php
get_footer()
;
  1. 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 in later lines.

Conclusion

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!

[ad_2]

Jaspreet Singh Ghuman

Jaspreet Singh Ghuman

Jassweb.com/

Passionate Professional Blogger, Freelancer, WordPress Enthusiast, Digital Marketer, Web Developer, Server Operator, Networking Expert. Empowering online presence with diverse skills.

jassweb logo

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet, and extranet products.

GSTIN is 03EGRPS4248R1ZD.

Contact
Jassweb, Rai Chak, Punjab, India. 143518
Item added to cart.
0 items - 0.00