Today I had the opportunity to help a new client fix a syntax error in WordPress. If you are seeing the same error instead of your website, then here is how you can get your site up.
WordPress is built using PHP, a programming language that by no means tries to guess the intentions of the programmer. So it will throw an error if it finds something strange or missing in the code as it is run/compiled/parsed.
Often such errors are human, for instance when a programmer is sloppy to leave unclosed quotes, misses or adds extra parentheses, misses a semicolon or a simple spelling error.
Because PHP is rigid in its rules, it will stop at the point where the parser encounters an error and gives up.
This error is then displayed on a browser showing the file, and the line number on the code – the point at which the parser finds the error.
This makes it easy to troubleshoot the syntax error. In the error below, for instance, you can see that there is an unexpected text in the code in class-oembed.php on line 421.
Beginners Guide: How to Fix the Syntax Error in WordPress Using 2 methods?
For the rest of us, let’s move on.
When troubleshooting syntax errors, I always look at what files are affected. Is it the theme or a plugin or is it the WordPress core files. Most times for core WordPress files and plugins I reupload new files.
If the error is related to your theme, or if you were editing something else, then you will need to access the server where the files sit.
Method 1 – Fix the Syntax Error with an FTP client.
Download, Install, and launch the program.
You will need the Host address, Username, Password and the port number (21).
If you use FileZilla, supply the required information and then click Quickconnect.
Once you log in, navigate to the folder containing the file shown on the error message. In my case it was /public_html/wp-includes.
You can right-click and then click View/Edit to edit it or download it. I always opt to download the file to the computer so I can make a copy of it before making any changes.
With the file saved to your computer.
Open the file you downloaded and scroll to the line number. In my case, it is in line 421.
If you saw the error after modifying code, check for anything strange, could it be a missing bracket, tag, or semicolon?
If that line looks fine, look at the previous lines of code. The line number shown is only where the parse gave up, the error could be on the last line. Check, for likely culprits.
Edit it and save. Then upload the file.
Reload your website.
Method 2 – Fix the Syntax Error within the host’s File Manager.
Now, that was editing the file with an FTP client. You can also select the file in your host’s control panel.
Navigate to the folder containing the file shown on the error message. In my case it was /public_html/wp-includes.
Then, right-click the file. Click Edit.
Scroll down the line in question. The cPanel code editor will show the exact place where the code breaks.
Go ahead and make changes.
After you save your change, reload the website. It should be back.
If it is not, clear the cache on your browser or on WordPress and try again.
It turns out my new client’s site was hacked into. I replaced all the WordPress files with a fresh copy. Voila, everything worked.
Finally, this should bring you to notice that anything can happen to your website. Hackers, human error, or a bizarre lightning strike and you are wiped off the internet.