How to fix Parse error: syntax error in WordPress

How to fix Parse error: syntax error in WordPress

Isn’t it scary when you’ve just started making your WordPress website, and you use some code snippet from the web to add new features to your site, and your site breaks down? It sure is! This can happen because of an improper syntax. It is critical to use proper syntax to avoid breaking your site.

You might’ve come across something like this,

syntax-error-final-1

Well, there is no need to panic because you’re not the only one to receive this error. A syntax error is most of the times not a difficult error to fix.

Why did you receive a syntax error?

You received a syntax error because the snippet of code that you used is placed within a theme file incorrectly or the code itself contains an error. The error might be a misplaced character or a tag in the code, or it might be missing altogether. Sometimes typos created during writing a code also cause a syntax error. Wrongly modifying an existing code is also a reason.

In the above image, you can see a syntax error I received because I created an array using square brackets ([) but never closed it in the functions.php of Twenty Seventeen theme.

How to fix the syntax error in WordPress?

Fixing the syntax error in WordPress is usually not a difficult task. You have to patiently rectify the error by the method we’ve explained further, and fix it.

Using FTP to fix the syntax error

filezilla

You’ll have to use an FTP program to fix the syntax error. Filezilla is an amazing FTP program which I use. Install the FTP program and connect it to your website.

Using the FTP program (Filezilla in this case) log in to your server. You’ll have to then navigate to your theme’s folder. Once you’re in the theme folder, you’ll find the file that contains the error. Download the file.

file-zilla-2

Following steps will enable you to find the file, go to wp-content > themes > name of theme > name of the file > Download.

You have an option to either remove the code which is causing the problem or correct the code.

file-zilla-3-modified

You can see that [ ‘ mango ‘,’ apple ‘ was not closed which caused the syntax error.

After downloading the file, you can open it to make changes. Once you’ve done the changes, replace the original file by uploading the new file and then refresh your website. It should work fine.

Debugging tools to troubleshoot the errors

There are many free tools available online to debug code. These tools will help you to troubleshoot the code if you’re unable to rectify the mistake in your code. These tools will help you by highlighting the missing elements of your code. There are also tools available that’ll help you step through the code so that you see how it works. You can see the results as all of these run the code. Following are some of the debugging tools that will help you.

Cloud 9

Cloud 9 is an interactive development environment (IDE) which runs 150 different code languages. It has a built-in debugger that lets you execute code, step over, step through, set breakpoints, etc. A free, as well as a paid account, is available (starting at $19 per month).

JS Bin

With JS Bin you can debug JavaScript, CSS, and HTML. This tool runs all three to show you how each of them interacts with each other. You just have to type your code and hit the button. This is an amazing tool if you have confusion between multiple codes. It comes with several options for each language.

jsdo.it

jsdo.it also runs JavaScript, CSS, and HTML. It highlights the issues with your syntax. This a good tool to see how your code works. The best part about this tool is that it’s built around a social network of the coding world (you can take advantage of libraries and shareable code).

JS Fiddle

With JS Fiddle you can select different types of frameworks and languages for JavaScript, CSS, and HTML. This is a useful tool to clean up your code.This tool is an excellent choice if you’re working with a team as you can save your code and collaborate with others.

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *

*

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