New 24/7 monitoring and daily cloud backups now included in every Shield Pro plan.

Parse error

How to fix a WordPress parse error or syntax error

Parse error syntax error unexpected means PHP found invalid code before WordPress could run. It usually happens after editing functions.php, a snippet plugin, or a corrupted upload. This tutorial shows how to find and fix the broken file fast.

Time: 10-25 minutes Level: Intermediate

What this problem looks like

Unlike vague critical errors, parse errors name the exact file and line. Common causes include a missing semicolon, unclosed bracket, pasted code outside PHP tags, or a bad edit to functions.php from the theme customiser.

You do not need wp-admin to fix this. Open the file via SFTP, correct or remove the bad code, and reload the site.

Never paste large code blocks into functions.php on production without a backup. One missing bracket takes the entire site offline.

Step 1: Decode the error message

A typical message looks like: Parse error: syntax error, unexpected end of file in /home/user/public_html/wp-content/themes/mytheme/functions.php on line 42. The path and line number are your map.

  • functions.php in your theme: undo recent custom code.
  • wp-content/plugins/code-snippets/: deactivate the snippet plugin via FTP.
  • mu-plugins/: remove the offending must-use plugin file.

Step 2: Fix functions.php safely

Open wp-content/themes/your-theme/functions.php. Go to the line in the error. Look for unclosed {, (, or missing ;. If you are unsure, comment out the recent block by wrapping it:

php
/*
Your recent custom code here
*/
Prefer a child theme or a snippet plugin with syntax checking over editing parent theme functions.php directly.

Step 3: Deactivate snippet and custom code plugins

If the path is inside wp-content/plugins/, rename that plugin folder to .off. Code Snippets, Insert Headers and Footers, and WPCode are frequent sources of parse errors after quick edits.

Step 4: Restore the original file

Download a fresh copy of the theme or plugin from the vendor ZIP and replace only the broken PHP file. Do not overwrite wp-config.php or uploads.

Step 5: Validate PHP before saving next time

On SSH, run php -l against a file before upload:

bash
php -l wp-content/themes/mytheme/functions.php

When to stop DIY and hire help

If the parse error points at WordPress core files you did not edit, files may be corrupted or infected. BugShield fixes syntax and core corruption at a fixed price with malware checks included when needed.

FAQs

Can I fix a parse error without wp-admin?

Yes. Parse errors are fixed by editing the named file via FTP or File Manager. Admin is not required.

Why did this happen after a theme update?

Custom code in a parent theme functions.php is overwritten or merged badly. Use a child theme for custom PHP.

What if the error says unexpected T_STRING?

Usually a missing semicolon or quote on the line above the one shown. PHP line numbers can point one line after the real mistake.

Should I reinstall WordPress core for parse errors?

Only if the error path is in wp-includes/ or wp-admin/ and you did not edit those files. Otherwise fix the named plugin or theme file.

Rather someone else fixed it?

Request a fix at a confirmed price. Named UK developer, secure Vault, direct chat.

Request a Fix