1. Home
  2. WordPress Tutorials
  3. How to Correct a Syntax Error in WordPress

How to Correct a Syntax Error in WordPress

Have you encountered the infamous unexpected syntax error message in WordPress? This is one of the many common WordPress error messages that you will come across while using the platform. A syntax error happens when you are manually editing code and have made a mistake. Coding in WordPress is not overly complex but is easy to mess up.

One simple typo, extra space, or missing bracket can cause any line of code to not work and potentially break your entire website. This will result in the unexpected syntax error, but don’t worry, WordPress will tell you the exact location where the error is occurring. Today, I will demonstrate how to correct a syntax error in WordPress.

How to Prevent Syntax Errors in the First Place

It’s very easy to understand how a syntax error could happen and they are quite common. It’s more important to understand if what you are coding will result in a syntax error in the first place. Many experts urge web developers to not rely on plugins and manually code features into their websites. Adding plugins to your website will slow it down. Although it is a very small slowdown, it can become noticeable when you add a lot of plugins. Many of the simpler plugins do not require complex code and are more efficient to code in.

Whenever you manually add code, you will notice that every line of code is numbered. If WordPress detects an error, you will see a red warning symbol next to that line’s number. This is a clear indicator that there is an error and a problem will occur. Always check for error indicators when coding in WordPress.

How to Correct a Syntax Error in WordPress

Today, I will demonstrate how to correct a syntax error in WordPress. You will not need any additional plugins. In fact, you may not actually have access to your website depending on the severity of the syntax error. You will need access to your cPanel, which is provided by your web host when you create an account.

You should also be aware of where the syntax error is located. If you recently added a code snippet, it should be obvious where the problem is. If not, the unexpected syntax error message will tell you which folder the file is in, the name of the file, and the exact line the error is on.

Let’s start by logging into the cPanel and clicking on the File Manager option. The File Manager will allow you to access all of the files related to your website.

Click on the File Manager option.

You need to locate the source of your syntax error. You should know the exact file location from the error message. Right-click on the appropriate file and select the edit option.

Select the "Edit" option.

A pop-up window will show up. This box will warn you to create a backup of your files before editing anything. Since an error has already occurred, making a backup is not advised, since it might overwrite an existing backup before the error happened. Click on the “Edit” button. A new tab will open containing all of the code from the file.

Click on the "Edit" button.

Scroll through all of the lines until you find the line with the error. You should see a red square with a white “X” inside. This means the error has happened here.

Here is the error symbol.

You need to find out what is causing the error. Here is a small list of common errors that beginners make when coding.

  • Spelling mistake
  • Unnecessary or extra punctuation (i.e “.”, “,”, etc)
  • Extra bracket (i.e “(“, “)”, “{“, “}”, etc)

Once you have corrected the syntax error in the file, you will no longer see the red square with a white “X” on that line. Click on the “Save Changes” button to finish.

Click on the "Save Changes" button.

Congratulations, you have successfully fixed your website’s unexpected syntax error message. Always double check that there are no error symbols when you add code in WordPress. It can cause a lot of headaches and can be very scary for beginners just starting out.

Use a Backup to Restore Your Website

Like most of the common error messages, you will receive in WordPress, this can be easily fixed if you have a backup of your website. Backups are easy to create and offer you a way to avoid extended downtime caused by errors. Every time you are about to edit code, add a new plugin, update a plugin, change themes, update a theme or any other major changes, you should create a backup. This will ensure you can revert back if something unforeseen happens.

For example, it is common for new plugin updates to have unforeseen compatibility issues or have bugs. If this happens to your website, you can simply revert back and avoid any damage or downtime. You may also consider rolling back the plugin version as well. Keep in mind that if an error message is the result of a server problem a backup will not resolve the problem.

Keep Your Website Error Free

No one’s goal is to have an error on their website, but it will happen. It doesn’t matter if you have 1 month or 10 years of experience, mistakes happen. The important thing is your reaction to the error. It is quite common for beginning developers to get frustrated when these errors occur, but you shouldn’t get frustrated. This slows down your response time.

Errors will happen and there are many lists that contain all of the most common WordPress errors and how to fix them. As long as you are aware of the issue and immediately respond to it, there is no need to get angry.

Is this your first time experiencing a syntax error in WordPress? What was the cause of your syntax error?

Author: Chris Racicot

Chris is the Support Manager at GreenGeeks and has been with the company since 2010. He has a passion for gaming, scripting and WordPress. When he’s not enjoying his sleep, he’s working on his guitar skills and fiddling with 3d printing.

Updated on January 14, 2018

Was this article helpful?

Related Articles

Leave a Comment

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