syntax error, unexpected in WordPress – causes and solutions

A small mistake in PHP code can take your whole site down. The steps below usually fix it fast.

Suddenly seeing “syntax error, unexpected …” on your WordPress site can be alarming. Your site shows a white screen or a cryptic error instead of your pages — stressful, especially if you’re not a developer. Fortunately, this common PHP error is usually easy to fix, even without deep technical knowledge. In this article I explain what the error means, how to recognize it, how to fix it, and how to prevent it from happening again.

What does “syntax error, unexpected…” mean?

A syntax error is like a grammar mistake in your website’s code. In other words: there’s a small error in the PHP code, so WordPress can’t understand or execute it. The word “unexpected” means PHP encountered something it didn’t expect — a bracket, comma, or other character in the wrong place. Often it’s just one missing or extra character (comma, semicolon, quote, bracket) that triggers the error. Small mistakes can have big consequences for your entire site.

When this happens, WordPress stops loading the site. You’ll see a parse error that tells you what went wrong and where in the code it happened. For example:

Parse error: syntax error, unexpected ')' in /path/to/website/wp-content/themes/your-theme/functions.php on line 123

In this example, there’s an unexpected ) on line 123 in functions.php — likely a missing ( or an extra closing bracket. Another example:

Parse error: syntax error, unexpected '}', expecting end of file in C:\xampp\htdocs\yoursite\wp-content\themes\twentyseventeen\functions.php on line 247

Here PHP found a } it didn’t expect (maybe an extra closing brace or a missing opening {). In all cases the message tells you the file and line number. That’s the key to fixing it.

How to fix the error

Once you see the syntax error, follow these steps to get your site back. You don’t need advanced programming knowledge — just a few targeted actions.

Step 1 – Read the exact error message

First: read the error carefully. It usually includes three elements: the error type (Parse/Syntax error), what was unexpected, and the location (file + line number). Note these details. They tell you exactly where to look.

Tip: if you see only a white screen or “There has been a critical error on this website”, WordPress may be hiding errors. Temporarily enable debug mode by changing define('WP_DEBUG', false); to true in wp-config.php. Reload the page and you should see the exact error (remember to turn debug mode off again later).

Step 2 – Check the file and code at the line

Now open the file mentioned in the error. Use your hosting file manager or FTP to locate the file (often a plugin file or your theme’s functions.php) and open it in a text or code editor.

Go to the line number in the error message. Look closely at the surrounding code. Check for missing or extra brackets, missing semicolons, or mismatched quotes. The “unexpected” part often points to the clue: unexpected ')' usually means an unmatched bracket; unexpected T_STRING often means a missing comma or semicolon before the text.

If you recently pasted or changed code, start there — the error is usually in the last change you made.

Step 3 – Fix the code

Once you find the suspicious code, correct it. Common fixes include:

  • Add a missing character: for example a } to close a block, a ) to close a function call, or a ; at the end of a statement.
  • Remove an extra character: maybe you accidentally left an extra bracket or brace.
  • Fix invalid syntax: a typo, an unclosed quote, or a missing $ for a variable can break PHP.

After editing, save the file and refresh your site. If the error disappears, you’re done. If another error appears, read it and repeat the steps — there may be multiple mistakes.

Tip: if you’re unsure, paste the code into a proper code editor (VS Code, Sublime Text, Atom). These editors highlight syntax problems, making it easier to spot missing semicolons or unmatched brackets before you upload the code.

Alternative: restore a backup

If you can’t find the error or don’t feel comfortable editing code, you can restore a backup. Most hosting providers create daily backups. Restore the version from before the error appeared. That should bring your site back.

If you have a manual backup of the affected file (for example the old functions.php), you can restore just that file instead of the full site.

Why use a backup? It’s the fastest way to get your site online if you can’t locate the error. Keep in mind you may lose changes made after the backup.

Common causes of “syntax error, unexpected”

How does this happen? The most common causes are:

  • Edits to plugin code: if you manually added code to a plugin file or pasted a snippet, a small typo can cause the error.
  • Editing theme files without checks: editing functions.php or other theme files directly in the WordPress editor is risky. One mistake can crash the site — and then you can’t access the dashboard to fix it.
  • Missing bracket or semicolon: the classic mistake. Forgetting a } at the end of a function or a ; at the end of a line breaks the rest of the code. These tiny errors are responsible for most syntax errors.
  • Copy‑pasted code from the internet: many people copy snippets from blogs or forums. If the snippet is meant for a different WordPress version, or you forget to wrap it in <?php ?> tags, you can trigger a syntax error. Copying code without understanding it increases the risk.

These errors almost always appear right after a code change. A syntax error doesn’t happen “out of nowhere” — there is usually a recent edit that triggered it.

How to prevent this in the future

You can’t prevent every syntax error, but these tips reduce the risk:

  • Use a child theme and never edit your live theme directly. With a child theme you can safely customize without breaking the parent theme. If the child theme breaks, you can revert easily. It also preserves your changes during theme updates.
  • Test code in staging or locally. Try new code on a staging copy or local install (XAMPP/Laragon) before adding it to your live site. If it fails, visitors never see it. If you don’t have staging, at least make a backup before editing.
  • Use a code editor with syntax checks. Editors like VS Code, Sublime Text, or Atom highlight syntax errors immediately. You’ll see missing quotes or brackets before uploading the code.
  • Make a backup before every code change or update. This is a golden rule. Before installing a plugin, updating a theme, or editing code, ensure you have a recent backup. That way you can recover quickly if something breaks.

With these precautions, you reduce the chance of syntax errors and limit the impact if they do happen.

Want this to stop being your problem?

If outages or errors keep repeating, the fix is often consistency: updates, backups and monitoring that don’t get skipped.

See managed WordPress hosting