WordPress 'Parse error: syntax error, unexpected' After Editing Code
A typo in a PHP file breaks the site. Find the line the error names and fix or undo the change.
Reference guide. This guide is written from established practice and the official documentation of the tools involved. We have not yet tested every step on a live demo site. Back up your site before you change anything.
A parse error means PHP could not read the file because of a typing mistake. The message tells you the file and line.
Step 1: Read the message
For example "syntax error, unexpected '}' in /wp-content/themes/mytheme/functions.php on line 52". The mistake is on that line, or just above it.
Step 2: Undo the last change
The fastest fix is to remove what you just added, or restore the old version of the file from a backup. Edit through File Manager or FTP, since the dashboard is not available.
Step 3: Common mistakes
- A missing semicolon
;at the end of a line. - Unmatched brackets, braces or quotes.
- Smart (curly) quotes pasted from a web page instead of straight quotes.
- Code pasted without the opening
<?phptag, or pasted inside another function. - Using newer PHP syntax on an old PHP version.
Step 4: Prevent it
Add custom code with a code-snippets plugin, which checks the code and disables it if there is an error, or use a child theme. See our theme guide.
Related
For a generic crash message, see our critical error guide.
Related guides
- WordPress White Screen of Death: How to Fix a Blank Page
- WordPress Theme Broke the Site: Switch Back to a Default Theme Without Dashboard Access
- WordPress Posts or Pages Show 404 Not Found but the Homepage Works
- WordPress Pages Show 404 Not Found (Posts Work, Pages Do Not)
Did this solve it? If not, email hello@sitefixlab.org with the exact error text and we will look into it. Try the problem finder.