How To Fix WordPress Syntax Error [3 Easiest Way in 2021]

I bet it breaks your heart when you see the following message or something similar to this.

Syntax error

— Unfortunately, a small scale error can cause your entire WordPress website to malfunction or even break entirely.

If you’re a novice in WordPress, it is only understandable that you freak out when something like this occurs. Do you feel you’ve taken all necessary steps, yet, you aren’t getting the desired results?

Don’t worry!

We’ve got you covered, how to fix WordPress syntax errors within the shortest possible time.

If you’re new to WordPress syntax errors, in that case, you should get an idea about syntax, itself.

What is syntax?

In layman’s terms, we can define syntax as the arrangement of various phrases and words for creating an understandable and well-formed language. — For programming, a syntax error happens in order.

Now, let’s come to the point of syntax errors and what exactly causes syntax errors in WordPress.

What’s a syntax error?

Critical Syntax Error

In most cases, you’ll see a syntax error occurring when you might not have written a certain command correctly. So, the compiler cannot parse your file, thus, as a result, it won’t display your WordPress site. You may see an error message similar to the one shown below.

Related Tips: How to install WordPress Plugins manually 

What Causes Syntax Error in my WordPress site?

You’ll notice that a parse error syntax looks like the one, as you can see below. You can get other types of errors to the one shown above. However, each error has similarities.

Syntax Error in WordPress

Parse error: Syntax Error:

As the name suggests, you will see this type of error when there’s a syntax error on your website.

Important Note:
Parse error is an error that you’ll see occurring because a task did not occur in the way it should have occurred.

Types of Parse errors:

Unexpected errors:

This is the next portion of the parse error. If you see the error saying ‘Unexpected $end’ then it means, you haven’t closed something properly. You might’ve missed out on possibly adding a parenthesis or maybe didn’t close the/a bracket.

Some of the unexpected $end errors you might face includes:

  1. Unexpected ‘=’: they commonly showed this error when you forget to include the $ sign while referencing a variable
  2. Unexpected ‘(’: you will see this when there is no (opening bracket) ‘(’
  3. Unexpected ‘)’: you will see this when there is no (closing bracket) ‘)’
  4. Unexpected T_STRING: you will see this when you have not added either a semicolon or a quotation mark just before the end of the previous line
  5. Unexpected T_ELSE: you will notice this when there is an else statement that has no opening if statement

Unexpected Errors

2. Syntax Errors – Due to missing characters or braces

A syntax error occurring would mean you’ve made a blunder while making the PHP structure. This might be, for example:

  • A missing semicolon (;) right the end of any given individual line
  • Any missing ‘curly’ quotation marks
  • Lastly, any missing curly brackets Basic structure of Syntax Errors

Basic structure of Syntax Errors

3. Undefined Constant Errors:

For this type of error, if you look closely, a character would be missing within an array. When you reference a variable or during other types of scenarios.

Structure of Undefined Constant Errors

 

How should I identify and solve Unexpected $end errors?

Whereas, you’ll see the error ‘unexpected ‘.’,’ you added something extra that wasn’t necessary. A period in the aforementioned case.

identify and solve Unexpected $end errors

The exact file:

This portion of the error will tell you the exact place where the error is located. You may find yourself to be a bit out of sorts if you haven’t ever accessed the files on another editor within the admin area of WordPress.

You need to keep a note of the exact file’s path where the problem exists.

The exact line:

You may face difficulty when editing your file on WordPress Editor. You will find various editors that will have your lines of code numbered. This is what the error is all about. It specifies the exact line where the error occurred. This will save you a lot of time and you won’t need to go through every line of code.

Ways in which you can access the website files:

1. Accessing your website’s files using FTP For fixing the Syntax Error in WordPress you will need to change the code/lines of code that caused the error(s). The most common way you can resolve this syntax error is to exchange the faulty code using the FTP.

Using an FTP client is the best bet for accessing your site’s necessary files when you cannot edit the file using WordPress editor. Using an FTP client you can access the files of your website through the host in cPanel.

You can choose your desired FTP client, but we are going to consider one of the widely used ones, FileZilla. You need to choose a version of FileZilla that is compatible with your OS.

Once you install and open the program within your system, you need to follow the steps below.

  • Click File
  • Select the Site Manager
  • Enter the Site’s name to label the site

Finally, input the settings below.

  • Host: Name of your domain domain.com
  • Port: You may leave this blank
  • Protocol: FTP Encryption: Use plain FTP only Logon
  • Type: Normal

Use your username & password to gain access to your website via your designated username & password in FileZilla. For example, if your host makes use of cPanel in that case use the designated username and password for signing in to cPanel.

Next up, you need to open up the Transfer Settings tab. Check limit the number of simultaneous connections. As for the Maximum Number of Connections, input 8. Lastly, you need to connect to your website’s files using the FTP server.

Identifying & fixing parse errors; Uploading files back to WordPress:

1. Fixing any Parse error by simply uploading the file’s fresh version

Another simple solution that you can consider using for fixing parse error, if you cannot fix your code can be to upload the file’s fresh version.

  1. Initially, if you’ve archived just the original folder and just have the updated theme through WordPress, in that case, you’d need to download a fresh copy of the file from your designated theme provider.
  2. If in general, there is a problem with your WordPress, then we suggest you download a fully fresh copy.
  3. You need to ensure that either the version of the WordPress or theme that you are downloading is the same as the one you’re using.
  4. However, you can always download older versions of WordPress simply by clicking on the Release Archive link within the menu on the left hand side from the download section.
For problems with wp-includes or wp-admin:
1. You will need to choose the WordPress root for issues with wp-includes or wp-admin
2. This way, you can securely upload fresh copies of the designated files to your website
3. We suggest you make sure to never upload a fresh copy of the wp-content, because this will result in deleting the contents of your WordPress website.

2. Fixing the Parse error: Syntax Error using FTP client

Let’s consider the error in the above image as an example.

As explained previously, the marked portion of the directory will tell you the file that contains the error. The remaining path of the file will show you its exact location.

Here, the function.php file contains the Zerif Lite theme folder, which consists of the main themes folder. This contains within the wp-content folder, on the website’s root directory.

Refer to the screenshot below.

Public html

For a majority of the sites, you will notice that the root directory is public_html. So, you will need to open that given file in FileZilla. After that, depending on the error you’re getting, you’ll need to locate the designated file containing the parse error.

Proceed with double right clicking the file for downloading it to your device.

Identifying the Parse Error:

You can easily open up a PHP file by using your designated default text editor from your device. Although, if you face difficulty identifying the error, on the editor, then we recommend you to download a text editor designed for programmers.

Some of the renowned text editors are listed below for your convenience.

  • TextWrangler
  • Sublime Text
  • Notepad++
  • Brackets
  • Atom

Identifying the Parse Error

Skim through the code snippets above. Here, as you can see, each line of code is numbered within this editor. Hence, this makes it a lot easier for you to find the specific line containing the error.

Fixing Parse Error: Syntax Error

Some of the common reasons why parse error might be displayed are as follows:

  1. Understand if the error is easy to begin with
  2. Cross check if you’ve either forgot to add any closing brackets or semicolons
  3. If you’re into pasting code on your file, you need to make sure that you’ve pasted the code correctly.
Useful Tips:
1 If you’re a relative beginner and copy/paste code, then make sure that you do not paste the code after the ?> tag.
2 Provided that you added any code outside the ?> tag then, make sure you’ve copied it before the ?> (closing) tag.
3 Lastly, if you’ve added a snippet of code by yourself but can’t find a way to correct the code, we suggest we consult a developer to solve this issue

c. Uploading your file back to your WordPress website:

  • Identify and fix the error
  • Save this given file on the text editor
  • Open FileZilla and ensure the folder containing the files are open
  • There are four panels within FileZilla, focus should be on the bottom two panels
  • You should open the folder on the right hand side
  • Use of the bottom left panel for navigating to the folder, where the file you edited is located

Uploading your file back

  • Drag the edited file from the left hand side to the right hand side panel
  • This way, you need to rewrite the original file when you’re prompted
  • Lastly, refresh the FTP client using the button right at the top
  • Refer to the image above
  • Refresh the page to ensure the parse error is resolved

Lastly, refresh the FTP client simply by clicking on the button right at the top. Refer to the image above. You need to refresh the page to be sure whether the parse error is resolved.

3. Fixing Parse Error via Control Panel:

You can also choose to fix the syntax error using cPanel.

  1. This would require you to log in to the cPanel and look for the — ‘File Manager’ option.
  2. Within the ‘File Manager’, you will be required to go to the ‘Code Editor’.
  3. Here, you need to look up for the precise lines of codes, where changes are necessary.
  4. Lastly, you will need to edit the file and click on the ‘Save Changes’ once you’re done.

Frequently Asked Question:

How can I avoid any possible Syntax Errors?

For this, we’d suggest you learn PHP from scratch. Because, if you’re proficient in PHP, then it will be a whole lot easier for you to be able to detect and debug errors simply by skimming through the code.

You should be able to avoid and fix any errors with relative ease if you have the necessary knowledge on PHP. Also, you should be able to look up for any syntax mistakes simply by running the code through a code validator.

Quick Tip for the most common syntax mistake:
You need to make sure that the functions are not broken up by each other.

How can I fix any Syntax Errors from my WordPress website?

A short video tutorial This is a short and simple video tutorial that will assist you to fix any syntax errors by simply following the given steps shown.

Why would it even matter for me to fix WordPress Syntax Error?

If you encounter a syntax error, that should be an indication as to something’s not quite right with your site’s code. This can cause your website to malfunction, giving off error messages or showing blank pages.

Whereas, if your site remains down or is not accessible, then it will affect the overall User Experience (UX). Having a blank page can also have a detrimental effect on your sites traffic as well as conversion rates.

— Lastly, this will also hurt your ranking for Search Engine Optimization.

Final Thoughts:

It is perfectly normal for you to either add or edit lines of code from your WordPress website. This is the norm, considering WordPress being open source.

Although, we suggest you to be vigilant when making any changes whatsoever.

—  Because even the slightest changes, as little as not adding a bracket can result in significant issues.

Nonetheless, this should not stop you from incorporating your own lines of code to your website. Because mistakes should act as a learning curve for you.


Disclosure: These posts often contain affiliate links referring to a clicking and purchasing of an item will generate some commission for our site. Positive reviews are genuine and are not based on any payments. Above statements reflect our findings on the respective theme.


2 Comments

Leave a Reply

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