More fixes

"Parse error: syntax error, unexpected ..." on a WordPress site

PHP, the language WordPress is written in, reads a whole file before it runs any of it. One wrong character - a missing semicolon, an extra brace, a curly quote pasted from a blog - and it refuses the entire file. If that file is your theme's functions.php, wp-config.php or an active plugin, every page and the admin go down together. The good news: the message names the exact file and line, and nothing in your content is lost. Below is a rebuilt example (not a real client), how to read the message, and the fix for each cause.

The shop page

What the checks found


  

First: read the message, then open the file outside WordPress

  1. Find the full message. Depending on your host's settings you see either the raw line - Parse error: syntax error, unexpected ... in /home/.../functions.php on line 42 - or WordPress's own "There has been a critical error on this website" page. In the second case the full line is in your host's error log (cPanel: Metrics > Errors, or error_log in the site's folder), and the site's admin email usually has a message titled "Your Site is Experiencing a Technical Issue" that names it too.
  2. Note the file and the line. The path tells you whose code it is: wp-content/themes/... is the theme, wp-content/plugins/name/... is that plugin, wp-config.php is the site's settings file. The line number is where PHP gave up, so the mistake is on that line or just above it - a missing ; or ) at the end of the previous line is reported on the next one.
  3. Open the file with the host's file manager or SFTP, not the WordPress editor. The admin is down too, and the WordPress theme editor would not let you save the broken code anyway (since 2017 it tests a PHP change and rolls it back if it breaks the site). Download a copy of the file before you change anything.

The causes, most common first

  1. A code snippet pasted with a mistake. A tutorial says "add this to your functions.php", and something got lost on the way: the last line, a closing brace, or the straight quotes, which a blog or a word processor turned into curly ones (‘ ’ “ ”). PHP only accepts straight quotes. Remove the block you pasted and save - the site comes back at once. Then add it again with straight quotes and every line ending in ;, or better, through the free Code Snippets plugin, which checks the code before it runs and switches off a snippet that breaks.
  2. An edit made through the host's file manager or FTP. These save whatever you type, with no check. That is often how a snippet the WordPress editor refused still reached the site. Same fix: restore the copy you downloaded, or undo the last change.
  3. A second <?php or some HTML pasted inside PHP. The message says unexpected '<' or unexpected token "<". A snippet that starts with <?php was pasted into a file that is already PHP. Delete the extra opening tag.
  4. A plugin or theme that needs a newer PHP than your server runs. Right after updating or uploading one, the error points inside that plugin's own folder and says something like unexpected '?', unexpected '=>' or unexpected '|'. The plugin is written for PHP 8 and the host still runs 7.x. Rename the plugin's folder in wp-content/plugins to switch it off, then either move the site's PHP version up in the host panel (after a backup, and after checking your other plugins support it) or install the plugin version that matches your PHP.
  5. A file only half uploaded. unexpected end of file in a plugin or theme file nobody edited usually means an FTP upload or an update was cut off. Delete that plugin's folder and install a fresh copy; your settings live in the database and stay.
  6. An edit to wp-config.php. Adding a line such as a memory limit or debug setting with a curly quote or no semicolon takes the whole site down, including the recovery email. Restore the copy, or retype the new line with straight quotes and a ; at the end.

What you see, what it means, what it needs

What the message saysUsual causeUsual fix
unexpected identifier or unexpected variable at the start of a lineMissing ; or ) at the end of the line beforeAdd it on the previous line
unexpected identifier next to words in quotes, or a curly quote in the messageCurly quotes from a blog or a documentRetype the quotes as straight ' or "
unexpected '}' or unexpected end of file in a file you editedA brace missing or one too manyRemove the pasted block, or match every { with a }
unexpected '<'A second <?php or HTML inside PHPDelete the extra opening tag
unexpected '?', '=>' or '|' inside a plugin you just updatedPlugin needs a newer PHPRename its folder; raise PHP or use the matching version
unexpected end of file in a file nobody touchedUpload or update cut offFresh copy of that plugin or theme

What not to do

Once you have the file and the line, the fix is usually one character or one pasted block. If you would rather hand it over, or you cannot get into the host's file manager, that is what the box below is for. Related: "There has been a critical error", a blank white screen, 500 Internal Server Error and a plugin conflict.