What a WordPress parse error means
The message Parse error: syntax error, unexpected is generated while PHP is parsing source code. Unlike a normal runtime error, PHP cannot successfully compile the affected file into executable instructions.
The message may name an unexpected token such as a variable, string, bracket or keyword. It can also say what PHP expected instead. That information is useful, but the actual mistake is not always on the exact line reported. A missing quote, semicolon or closing bracket on the previous line can cause PHP to complain when it reaches the next otherwise valid statement.
If the error appeared directly after editing PHP in a theme, plugin, snippet or wp-config.php, start with that change. If it appeared after an update or server migration, the failing path can help identify incompatible or damaged code.
Common causes of WordPress syntax errors
Most parse errors come from a small number of structural mistakes in PHP code.
- A missing semicolon at the end of a statement.
- An unmatched opening or closing parenthesis, square bracket or curly bracket.
- A quotation mark opened but not closed correctly.
- Code pasted into the wrong place, including PHP code placed outside PHP tags.
- A malformed function, class, array or conditional statement.
- Partially uploaded or damaged plugin or theme files.
- Syntax that the server's PHP version does not support, particularly after moving a site between servers with different PHP versions.
Automatic editors can also introduce problems when code is copied through software that substitutes typographic quotation marks or alters characters. A proper plain-text code editor is safer for PHP changes.
How to fix a WordPress parse error safely
Take a full backup of both files and database before editing or replacing anything. If the site stopped immediately after your own edit, preserve a copy of the broken file before restoring it so you can compare the change later.
- Read the error carefully and note the complete file path, reported line and unexpected token. Check several lines before the reported line as well as the line itself.
- If you just changed that file, undo the most recent edit. Restoring the known working version is usually safer than making several speculative syntax changes on a live site.
- If the error belongs to a plugin or theme update rather than your own code, reinstall or restore a clean copy of that same component from a trusted source. Do not edit WordPress core files to compensate for broken plugin or theme code.
- If wp-admin cannot load and the failing file belongs to a plugin, temporarily rename that plugin's directory inside wp-content/plugins. If the site returns, keep the component disabled until its code has been corrected or replaced.
- Where command-line PHP is available, linting the exact PHP file can confirm whether it parses without executing it:
Make sure the command uses a PHP version representative of the site's server environment.php -l path/to/file.php - If the screen does not show enough information, enable WordPress logging on a staging or controlled environment rather than displaying errors to visitors:
Disable debugging when the investigation is complete.define('WP_DEBUG', true); define('WP_DEBUG_LOG', true); define('WP_DEBUG_DISPLAY', false);
Avoid deleting wp-config.php, WordPress core files or database records to address a syntax error. The reported source file should be repaired, restored or replaced appropriately.
When to stop fixing a WordPress parse error yourself
Stop if the failing file contains custom business logic, payment code or unfamiliar modifications, or if restoring the affected plugin or theme does not remove the error. A repeated parse error after deployment can point to an incomplete release process, incompatible PHP syntax or more than one damaged file.
It is also worth escalating if the site was modified without your knowledge. Unexpected edits to plugin or theme files can require a wider security investigation rather than a single syntax correction.
Web Support Services offers an Emergency Fix for £249 per incident with a response within 2 working hours. Care plans start from £59 a month for ongoing maintenance and support.