How to Fix Syntax Errors on WordPress
access_time
hourglass_empty
person_outline

How to Fix Syntax Errors 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:

Step 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 appears on the homepage

We can see that the error is caused by the 72nd 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.

Step 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.
    locating syntax error in index.php file
    We can see that a very important part is missing — a semicolon to end the get_footer function.

    If you are a novice in PHP, use a PHP code checker and see the most common PHP syntax mistakes. These tools will help you debug the error and fix it.

  3. Place the semicolon on the 72nd line.
    <?php
    get_footer()
    ;
  4.  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.

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!

The Author

Author

Domantas G. / @domantas

Domantas leads the content and SEO teams forward with fresh ideas and out of the box approaches. Armed with extensive SEO and marketing knowledge, he aims to spread the word of Hostinger to every corner of the world. During his free time, Domantas likes to hone his web development skills and travel to exotic places.

Related tutorials

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Become a part of Hostinger now!

More in WordPress
How to create custom widget in WordPress
How to Create a WordPress Custom Widget: A Step-by-Step Guide

Close