How to Fix WordPress Parse Error: Complete Guide
The WordPress parse error is one of the most common — and most alarming — errors a site owner can encounter. The message usually reads Parse error: syntax error, unexpected T_STRING in /path/to/file.php on line X, and it can take an entire site offline in an instant, including the wp-admin dashboard.
Unlike the White Screen of Death, the parse error is refreshingly specific: PHP stops executing because it cannot understand the code, and it tells you exactly which file and line broke. This guide explains what the error means, why it happens, and how to fix it step by step — whether the culprit is a missing semicolon in functions.php, a stray bracket in a plugin, or a byte-order mark (BOM) introduced by a rich text editor.
What is the WordPress Parse Error?
A parse error (sometimes called a syntax error) occurs when the PHP engine reads your code and finds something it cannot interpret as valid PHP. Because PHP is a compiled-on-the-fly language, the parser evaluates each file before it runs. If it hits an unexpected token — an unclosed string, a missing semicolon, an extra brace — it stops immediately and refuses to execute the rest of the file.
In WordPress this means that a single malformed line in functions.php or a plugin file can disable the whole site, because the broken file is included during the normal load sequence. The error message is typically formatted as follows:
Parse error: syntax error, unexpected token "&" in /var/www/html/wp-content/themes/mytheme/functions.php on line 42
The line number is usually accurate to within a line or two, which makes the error straightforward to track down — provided you can still access the file.
Common Causes
Parse errors almost always appear immediately after a change — an edit, an update, or a migration. The most frequent triggers are:
- Missing semicolon — PHP statements must end with a semicolon; omitting one makes the parser concatenate two statements.
- Unclosed bracket or brace — a missing
),], or}shifts everything that follows into the wrong context. - Incorrect PHP in functions.php — the most-edited theme file is also the most common source of parse errors.
- Plugin code error — a plugin update may ship with a bug, or a copy-paste into a plugin file may introduce invalid syntax.
- BOM encoding — saving a PHP file as UTF-8 with BOM inserts invisible bytes at the start that PHP emits as output, breaking headers and sessions.
- PHP version incompatibility — code using array short syntax or nullable types may parse cleanly on PHP 8.x but fail on PHP 5.6.
Step-by-Step Fix Guide
Step 1: Read the Full Error Message
The error message names the exact file and line. Write both down before you do anything else. If display errors are off and you only see a blank page, enable WP_DEBUG in wp-config.php to surface the message.
Step 2: Access the File via FTP/SFTP
Because the parse error often locks you out of wp-admin, you will usually need FTP/SFTP or a host file manager. Connect to your server and navigate to the path shown in the error.
Step 3: Fix the Syntax Error
Open the file in a plain-text editor, jump to the reported line, and correct the syntax. A missing semicolon, an unmatched quote, or an extra brace is the usual culprit. Save the file as UTF-8 without BOM.
Step 4: Remove BOM Encoding
If the file looks correct but the error persists, hidden BOM bytes may be present. Re-save the file with encoding set to UTF-8 (no BOM), or strip the bytes from the command line.
Step 5: Check PHP Version Compatibility
Review the PHP version your host runs and compare it against the theme or plugin requirements. Code written for PHP 8.x may use syntax unsupported on PHP 5.6, and vice versa.
Step 6: Re-enable Components and Verify
Once the file is corrected, reload the site. If you had disabled plugins or switched themes to isolate the issue, re-enable them one at a time, reloading after each change so a recurrence points to a single component.
PHP Diagnostic Commands
From the command line you can lint a file without executing it, search for the offending construct, and manage plugins without touching wp-admin:
# Lint a single PHP file for syntax errors
php -l wp-content/themes/mytheme/functions.php
# Lint every PHP file in the active theme
find wp-content/themes/mytheme -name "*.php" -exec php -l {} \;
# Search for the line number reported in the error
grep -n "add_action" wp-content/themes/mytheme/functions.php
// Temporarily enable debug output in wp-config.php
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', true);
# Strip a UTF-8 BOM from the offending file
sed -i '1s/^\xEF\xBB\xBF//' wp-content/themes/mytheme/functions.php
# Deactivate a suspect plugin via WP-CLI when wp-admin is unreachable
wp plugin deactivate suspect-plugin --path=/var/www/html
# Check the PHP version running on the server
php -v
Quick Reference Table
| Symptom | Likely Cause | Fix |
|---|---|---|
| unexpected '&' / T_STRING | Missing semicolon on the previous line | Add the semicolon, then re-lint with php -l |
| unexpected end of file | Unclosed brace or parenthesis | Balance every { with a } |
| unexpected '<' | Raw HTML inside a PHP block | Close the PHP tag or echo the HTML |
| headers already sent | BOM or whitespace before <?php |
Re-save as UTF-8 without BOM |
| unexpected '?' | Nullable type syntax on PHP < 7.1 | Upgrade PHP or rewrite the signature |
| Parse error after plugin update | Bad code shipped in the update | Roll back the plugin or deactivate via WP-CLI |
FAQ
Why does the parse error appear right after a simple edit?
Almost every parse error follows a change. Even a single deleted semicolon or an unmatched quote pasted into functions.php is enough to halt the PHP parser. The error appears instantly because WordPress re-reads the file on every request.
Can a plugin update cause a parse error?
Yes. A plugin author can ship a release containing invalid PHP, and on update the broken file replaces the working one. Roll back to the previous version or deactivate the plugin through FTP (rename its folder) or WP-CLI until a fix is released.
How do I fix a parse error when I cannot access wp-admin?
Use FTP/SFTP or your host's file manager. Rename the offending plugin folder to disable it, or edit the theme file directly. If the active theme is broken, rename its folder so WordPress falls back to a default theme and restores access to wp-admin.
Will upgrading PHP fix the parse error?
Only if the error stems from version incompatibility — for example, code using the short array syntax [] on PHP 5.3, or nullable parameters on PHP < 7.1. If the cause is a genuine typo, upgrading PHP will not help; the syntax must be corrected at the source.
Conclusion
The WordPress parse error looks catastrophic but is almost always a single-character mistake. Read the file and line number in the message, open the file over FTP/SFTP, and fix the syntax — a semicolon, a brace, or a BOM. Lint with php -l, confirm the PHP version, and re-enable components one at a time. Keep WP_DEBUG on while you work, and your site will be back online within minutes.