Website support, maintenance and fixes for UK businessesCall 0208 088 8371info@websupportservices.co.uk

HomeWordPress errorsFix WordPress parse error: syntax error, unexpected

Fix WordPress parse error: syntax error, unexpected

A WordPress parse error means PHP cannot understand the structure of a PHP file, so execution stops before the affected code can run. The error normally gives a file path, an unexpected token and a line number that narrow down where to look.

The message you might see

Parse error: syntax error, unexpected

Different wording, or a file path in the message? Paste it into our free error finder to see which plugin or theme it comes from.

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.

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. Where command-line PHP is available, linting the exact PHP file can confirm whether it parses without executing it:
    php -l path/to/file.php
    Make sure the command uses a PHP version representative of the site's server environment.
  6. If the screen does not show enough information, enable WordPress logging on a staging or controlled environment rather than displaying errors to visitors:
    define('WP_DEBUG', true);
    define('WP_DEBUG_LOG', true);
    define('WP_DEBUG_DISPLAY', false);
    Disable debugging when the investigation is complete.

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.

Common questions

Answers to the questions we hear most about this.

Why does a WordPress parse error point to the wrong line?

PHP reports where parsing finally became impossible. The original mistake can be slightly earlier, such as an unclosed quote or bracket on the preceding line.

Can I still fix a syntax error if wp-admin is unavailable?

Yes. After taking a full backup, use SFTP or the hosting file manager to restore the changed file or temporarily rename the specific failing plugin directory if the error clearly comes from that plugin.

What does php -l do?

The PHP command-line lint option checks the syntax of a PHP file without running the application. It is useful for confirming that an edited file parses correctly before it is deployed.

Site down or showing an error?

Call us now. Emergency Fix is £149 with a response within 2 working hours, and no fix means no fee.

Get website support