Parse Error: Syntax Error

Parse Error: Syntax Error

Elena Rodriguez ·

Symptoms

  • White screen with 'Parse error: syntax error, unexpected...' message
  • Site displays 'There has been a critical error on this website' after editing code
  • WordPress admin dashboard inaccessible after plugin or theme update
  • Fatal error referencing a specific PHP file and line number

You edited a theme file, pasted a snippet from a blog post, or updated a plugin — and now your entire site is dead. The screen shows something like Parse error: syntax error, unexpected '}' in /wp-content/themes/yourtheme/functions.php on line 47. This is PHP telling you it hit something it can’t interpret. The good news: this is almost always fixable in under five minutes.

What Causes Parse Error: Syntax Error?

  1. Missing or extra brackets, parentheses, or semicolons — The most common cause. One missing ; or an unclosed { breaks the entire file.
  2. Pasting code with curly (smart) quotes — Word processors and some websites convert straight quotes (' ") to curly quotes (' "). PHP doesn’t understand curly quotes.
  3. Incompatible PHP version — Code written for PHP 8.x may use syntax that doesn’t exist in PHP 7.4, or vice versa. Plugin updates sometimes introduce newer PHP syntax your server doesn’t support.
  4. Editing files with the wrong encoding — Saving a PHP file as UTF-16 or with a BOM (byte order mark) injects invisible characters that break parsing.
  5. Incomplete code snippets — Copying a snippet from a tutorial that was missing its opening <?php tag or closing bracket.

How to Fix It

Step 1: Read the Error Message

The error message tells you exactly where the problem is. Look for two things: the file path and the line number.

Parse error: syntax error, unexpected '}' in /var/www/html/wp-content/themes/flavor starter theme/functions.php on line 112

Write down the file (wp-content/themes/flavor starter theme/functions.php) and the line (112). The actual problem is usually on that line or the one just above it.

Step 2: Enable Debug Mode (If You Can’t See the Error)

If your site shows the generic “critical error” screen instead of the actual parse error, enable debugging. Connect via FTP or SSH and edit wp-config.php in your WordPress root:

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', true );

Save and reload. The full error with file path and line number will now display. If you still can’t see it on screen, check wp-content/debug.log for the details.

Step 3: Fix the File via FTP or File Manager

Since the parse error likely locked you out of wp-admin, you can’t use the built-in theme editor. Use FTP (FileZilla, Cyberduck) or your host’s File Manager to access the broken file.

Navigate to the file from the error message — for example:

/wp-content/themes/yourtheme/functions.php

Open it and go to the line number from the error. Look for:

  • Missing semicolons at the end of a line: echo 'hello' should be echo 'hello';
  • Unclosed brackets: every { needs a matching }
  • Curly quotes: replace ' and " with straight ' and "
  • Stray characters: random text outside of <?php... ?> tags

Fix the issue, save, and reload your site.

Step 4: Revert the File If You Can’t Find the Error

If you can’t spot the syntax mistake, the fastest recovery is reverting the file. If you have a backup, restore the original file via FTP.

No backup? If the error is in a theme file, download a fresh copy of your theme from WordPress.org or your theme vendor and replace the broken file.

If the error is in a plugin file, rename the plugin folder to deactivate it:

# Via SSH
mv wp-content/plugins/broken-plugin wp-content/plugins/broken-plugin.disabled

Or use WP-CLI if it’s available on your server:

wp plugin deactivate broken-plugin --path=/var/www/html

Step 5: Check Your PHP Version

If the error appeared right after a plugin or theme update — and the code looks correct — your PHP version might be too old. Log into your hosting control panel (cPanel, Plesk, or your host’s dashboard) and check which PHP version you’re running.

Most modern WordPress plugins require PHP 7.4 or higher. The right move: upgrade to PHP 8.1 or 8.2. Every major host lets you change this in one click.

After changing PHP versions, reload your site.

Step 6: Turn Off Debug Mode

Once the error is resolved, switch debug mode back off in wp-config.php:

define( 'WP_DEBUG', false );
define( 'WP_DEBUG_LOG', false );
define( 'WP_DEBUG_DISPLAY', false );

Skip this if you want headaches later — leaving WP_DEBUG_DISPLAY on in production leaks file paths and PHP details to every visitor on your site. That’s a security risk you don’t need.

Prevention

  • Never edit theme or plugin files directly in production. Use a child theme for customizations, and test code changes on a staging site first. Every decent host (Kinsta, SiteGround, WP Engine) offers one-click staging.
  • Use a code editor, not a word processor. VS Code, Sublime Text, or even Notepad++ will preserve straight quotes and proper encoding. Google Docs and Microsoft Word will silently corrupt your PHP.
  • Keep PHP updated. Running PHP 7.4 or older means you’re one plugin update away from a parse error. Set a calendar reminder to check your PHP version quarterly.
  • Install a code snippets plugin like WPCode instead of pasting PHP into functions.php. It sandboxes each snippet so a syntax error in one doesn’t take down your whole site — and it has built-in error detection that auto-deactivates broken snippets.

Last verified: April 2026