Family Encyclopedia >> Electronics

How to fix syntax error in WordPress

There are a plethora of WordPress tutorials, guides, and code snippets available on the web. They are all intended for users to try new things on your website and learn more about WordPress. Unfortunately, one small mistake can cause the entire site to break, which is very scary, especially for new users. If you were trying something new on your WordPress site and got the following error "Syntax error, unexpected...", then don't panic. You are not the first to receive the syntax error in WordPress, and you will not be the last. In this article, we will show you how to fix unexpected syntax error in WordPress.

Use proper syntax to avoid errors

How to fix syntax error in WordPress

The first thing you should do is look at the beginner's guide to pasting web snippets into WordPress. This article lists some very common mistakes made by beginners when pasting code into WordPress templates. The syntax error is usually caused by a small but crucial error in the syntax of your code. A missing comma, or an extra square bracket can break the whole script.

Have you recently pasted a snippet from the web? Have you updated a plugin? Then chances are you know exactly where to look.

Video Walkthrough

Subscribe to WPBeginner

If you don't like the video or need more instructions, continue reading.

Fixing the syntax error using FTP

To fix the syntax error, you must edit the code that caused this error. You can remove it or fix the syntax. Often beginners go crazy because this error makes their entire site inaccessible. If you pasted the code using your WordPress panel Appearance »Editor section, then you are blocked. So how to edit the code? Take a look at our guide on locked WordPress admin. The only way to fix this problem is to access the file you last edited using FTP (How to use FTP).

After installing the FTP program, connect it to your website and go to the theme file that needs editing. In case you have forgotten which file you need to edit, just look at the error code. The error will tell you exactly which file and which line you need to edit.

You can remove the last code you added or write the code with the correct syntax. Once you are done removing/editing the code, save the file and upload it back to your server. Come to your WordPress site and refresh the page, and your site will work.

We hope this article helped you to fix WordPress syntax error. Please leave your questions and comments in the comments.