Fix Parse error: syntax error in WordPress PHP Files

beginner📝 WordPress2026-03-18| WordPress 5.x–6.x, PHP 7.4–8.3, Apache/Nginx, Linux/Windows

Error Message

Parse error: syntax error, unexpected '}' in /path/to/wordpress/wp-content/plugins/my-plugin/my-plugin.php on line X
#wordpress#php#syntax error#parse error

The Error

You edited a plugin or theme file, saved it, refreshed the site — and now you're staring at a blank screen or this:

Parse error: syntax error, unexpected '}' in /path/to/wordpress/wp-content/plugins/my-plugin/my-plugin.php on line X

Other variants include unexpected '{', unexpected 'T_STRING', and unexpected end of file. Different tokens, same root cause: PHP couldn't parse the file because the syntax is broken.

What Actually Happened

PHP parses every line of a file before running any of it. One syntax error anywhere, and it stops dead — no partial execution, no fallback.

Here's the part that trips people up: the line number in the error is where PHP noticed the problem, not necessarily where you made the mistake. A missing semicolon on line 23 can surface as an error on line 31.

Common causes:

  • Missing semicolon at the end of a line
  • Unmatched curly braces {} or parentheses ()
  • Unclosed string (missing closing quote)
  • Pasting code from Word or Google Docs with “smart quotes” instead of straight quotes
  • PHP version mismatch — e.g., using match() on a server still running PHP 7.3
  • Bad copy-paste that silently broke the code structure

Quick Fix: Get Your Site Back Online First

If the site is down, don’t start debugging blind. Restore access first, then fix the bug.

Option 1: Rename the broken file via FTP/SSH

Rename the offending file so WordPress skips loading it:

# Via SSH
mv wp-content/plugins/my-plugin/my-plugin.php wp-content/plugins/my-plugin/my-plugin.php.bak

That deactivates the plugin instantly. If the broken file is in a theme, rename the entire theme folder — WordPress falls back to the default theme automatically.

Option 2: Disable the plugin via database

No file system access? Go into phpMyAdmin or run this SQL directly:

-- Find active plugins
SELECT option_value FROM wp_options WHERE option_name = 'active_plugins';

-- Deactivate all plugins at once (nuclear option)
UPDATE wp_options SET option_value = 'a:0:{}' WHERE option_name = 'active_plugins';

Not subtle — it kills every active plugin at once. But it gets wp-admin working again so you can fix things properly.

Option 3: WP-CLI

wp plugin deactivate my-plugin --skip-plugins --skip-themes

Finding the Actual Bug

Site back up? Open the broken file and jump to the line number in the error. Then check one or two lines above it — that’s usually where the real mistake is hiding.

PHP’s built-in linter

Run this before uploading any PHP file:

php -l wp-content/plugins/my-plugin/my-plugin.php

Clean file:

No syntax errors detected in my-plugin.php

Broken file:

Parse error: syntax error, unexpected '}' in my-plugin.php on line 47
Errors parsing my-plugin.php

Takes under a second. Could save you a lot of back-and-forth with FTP.

Common patterns to look for

Missing semicolon:

// Broken
$price = get_post_meta($post_id, 'price', true)
echo $price;

// Fixed
$price = get_post_meta($post_id, 'price', true);
echo $price;

Unmatched braces:

// Broken — two braces opened, only one closed
function my_function() {
    if ($condition) {
        do_something();
}

// Fixed
function my_function() {
    if ($condition) {
        do_something();
    }
}

Unclosed string:

// Broken
$message = "Hello, world;
echo $message;

// Fixed
$message = "Hello, world";
echo $message;

Smart quotes from copy-paste:

// Broken — “” are not valid PHP string delimiters
$key = “my_option_key”;

// Fixed
$key = "my_option_key";

Permanent Fix Workflow

Editing live files is how you end up here in the first place. Stop doing that.

1. Use a local dev environment

# LocalWP, XAMPP, or Docker
# Edit locally, test there, deploy only when it works

2. Add PHP linting to your editor

VS Code: install PHP Intelephense or PHP CS Fixer. Both highlight syntax errors in real time — before you even save the file.

3. Pre-commit lint hook (if using Git)

# .git/hooks/pre-commit
#!/bin/bash
for file in $(git diff --cached --name-only | grep \.php$); do
    php -l "$file"
    if [ $? -ne 0 ]; then
        echo "PHP syntax error in $file — commit aborted"
        exit 1
    fi
done

4. Enable WP_DEBUG only on staging

Add this to wp-config.php on staging — never on production:

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

Errors get written to wp-content/debug.log instead of blowing up the frontend.

Verify the Fix

  • Run php -l your-file.php — confirm “No syntax errors detected”
  • Re-activate the plugin from wp-admin → Plugins
  • Visit the site — no white screen, no parse error
  • Check wp-content/debug.log for any lingering PHP warnings

If the Error Keeps Coming Back

If the syntax looks fine but the error persists, the file might be corrupted from a bad FTP transfer. Switch to binary mode:

# In your FTP client: set transfer mode to Binary
# Better yet, use SCP or SFTP — they don't touch the file contents at all

Also verify your server’s PHP version matches what the plugin requires. A plugin built for PHP 8.0+ that uses named arguments or match() expressions will throw parse errors on any PHP 7.x server.

# Check PHP version
php -v

# Or in WordPress
wp eval 'echo PHP_VERSION;'

Related Error Notes