Troubleshooting · Troubleshooting
How to Fix PHP Parse and Syntax Errors in WordPress
Short answer
A WordPress parse error means PHP could not read one file, so that file never runs and the site stops loading. Read the file path and line number in the message, then open that file through SFTP or your host file manager. Fix the bad line, often a missing semicolon or bracket, and reload the site to check the fix.
Key takeaways
- A parse error stops PHP before it runs the file, so the front end and wp-admin can both go down.
- The message names the file and line, but the real mistake is often on the line just before it.
- WordPress.org lists a missing semicolon, curly quotation marks and a missing curly bracket as common causes.
- Rename a broken plugin folder to turn that plugin off when you cannot reach wp-admin.
- Run php -l on the file after each edit until PHP reports no syntax errors detected.
- WordPress recommends PHP 8.3 or newer as of November 2026, and still works with PHP 7.4 or newer.
What does “Parse error: syntax error, unexpected” mean in WordPress?
A parse error means PHP met a token it did not expect, so it stopped reading the file before running any of it.
PHP is the language WordPress runs on, and it reads a whole file before it runs the code inside it. When one line breaks PHP grammar, the file fails as a unit. If that file belongs to your active theme or an active plugin, every page can stop, including wp-admin.
WordPress.org lists this error among its common WordPress errors, and it notes that PHP errors can show as a white screen when error display is off. That is why you may see only a blank page instead of the full message.
A 500 internal server error guide covers a different failure, where the server stops without naming a bad line of code.
How do you read the file path and line number in the message?
The message names the exact file and the line where PHP gave up, and those two facts point you to the fix.
A typical message looks like this: Parse error: syntax error, unexpected token "}", expecting ";" in /home/example/public_html/wp-content/themes/your-theme/functions.php on line 42. Read it in three parts: the unexpected token, the file path, and the line number.
The token is the word or symbol PHP could not place, such as } or a variable name. The file path is the full server path, so strip the part before wp-content to find the file. The line number is where PHP stopped, not always where the mistake sits.
WordPress.org says the reported line may not be the exact line, so check just before and just after it. Look at the 5 lines above it first, because a missing semicolon on an earlier line often makes PHP fail on the next line. The common WordPress errors page gives this same reading rule.
| Part of the message | What it tells you | Where to look first |
|---|---|---|
| Unexpected token | The symbol PHP could not place | The end of the statement before it |
| File path | Which theme, plugin or core file failed | The folder named in the path |
| Line number | Where PHP stopped reading | That line and the 5 lines above it |
What usually causes this error?
Most parse errors come from a small edit: a missing semicolon, a missing bracket, or a wrong quote character.
WordPress.org names three common causes in its common errors guide: a missing ; at the end of a line, curly quotation marks instead of straight quotes, and a missing curly bracket. Each one breaks the structure of the file, even when the rest of the code is fine.
Other triggers follow the same pattern. A snippet pasted from a web page can carry curly quotes, a copied function can lose its closing brace, and a variable can lose its $ sign. An update can also bring code that needs a newer PHP version than your server runs.
| Message clue | Likely missing character | Check this first |
|---|---|---|
Unexpected = | The $ before a variable name | The variable on that line |
Unexpected ) | The opening bracket ( | The function call above it |
Unexpected ( | The closing bracket ) | The condition above it |
Unexpected T_STRING | A quotation mark or a semicolon | The end of the previous line |
Unexpected T_ELSE | An if statement before the else | The block above the else |
WordPress.org lists these five clues in its common errors guide, with the missing character for each one. A related fatal error, where PHP names a function it cannot find, is a different problem and is covered in the call to undefined function guide.
How do you get back into your site when wp-admin is down?
Use the Recovery Mode link in the admin email first, and use SFTP or your host file manager if no email arrived.
WordPress added Recovery Mode in version 5.2. When a fatal PHP error is found during a normal page load, WordPress emails the site admin a special login link. That link pauses the faulty plugin or theme for your session only, so you can log in and turn it off.
If the email did not arrive, log in to SFTP or your host file manager and go to wp-content/plugins. Rename the folder of the plugin named in the error, for example from my-plugin to my-plugin-off. WordPress then stops loading its broken file.
WordPress.org gives a second method for turning off every plugin at once: rename the whole plugins folder to plugins.hold, log in, then rename it back to plugins and switch plugins on one by one. The Recovery Mode guide explains the email link in full.
How do you fix a broken functions.php file step by step?
Remove or repair the code you just added, then check the file with php -l before you reload the site.
Most parse errors in a theme sit in wp-content/themes/your-theme/functions.php, where site owners paste custom code. Keep a copy of the broken file before you change it. A WordPress backup guide shows how to save files and the database first.
- Open the file through SFTP or your host file manager and go to the reported line.
- Look at the 5 lines above it for a missing semicolon, bracket or quote.
- Delete only the code you just added if you cannot spot the fault, then save the file.
- Run
php -l wp-content/themes/your-theme/functions.phpif you have shell access, and repeat the edit until it passes. - Reload your home page and wp-admin to confirm both load.
Do not edit the file in a word processor, because it can add curly quotes and hidden characters. Use a plain text editor or a code editor with PHP syntax highlighting. If the file still fails after you remove your added code, replace it with a clean copy from the theme download or your backup.
How do you fix the error in a plugin file?
Rename the plugin folder to turn it off, then reinstall a clean copy of the plugin or repair the named file.
When the message names a path under wp-content/plugins/plugin-name/, the fault sits inside that plugin. Renaming its folder, for example to plugin-name-off, stops WordPress loading it and brings the site back. This does not repair the file, but it gives you a working dashboard while you work.
Next, decide between a clean reinstall and a repair. A clean reinstall is safer when you did not edit the plugin yourself, because it replaces every file with the published version. Delete the renamed folder only after you have a copy, then install the same plugin version again.
Repair the file only when you edited it yourself and you know what changed. Open the named file, check the reported line and the lines above it, and fix the missing character. Then run php -l on that file.
DreamHost notes the same order: find the named file, fix the line, and check the site again (DreamHost common WordPress errors).
How do you fix a parse error in wp-config.php?
Open wp-config.php in a plain text editor, fix the line the message names, and save it as plain UTF-8 without a BOM.
A parse error in wp-config.php stops the whole site, because WordPress loads that file on every request. WordPress.org notes that this can happen right after a fresh install when a syntax error is introduced into it. Open the named file and check the reported line and the lines above it.
Common faults here are a missing semicolon after a define() line, a curly quote pasted from a web page, or a missing $ before a variable.
Check that the file starts with the opening PHP tag and no blank lines before it. Save it as plain UTF-8, not UTF-8 with BOM, because the BOM counts as output before PHP starts.
If you cannot spot the fault, compare your file with the sample file from a fresh WordPress download, line by line, and copy only the settings that differ, such as the database name, user, password and host.
How do you check the file with php -l before you upload it?
Run php -l filename.php on the file, and upload it only when PHP prints “No syntax errors detected”.
PHP ships with a lint option, -l, that checks syntax without running the code. The PHP manual says -l means “syntax check only (lint)”.
On success it writes No syntax errors detected followed by the file name. On failure it writes Errors parsing plus the parser error, and sets the shell return code to -1.
Use it after every edit. Fix one fault, run php -l again, and repeat until it passes. This catches a second missing bracket that the first error hid, because PHP stops at the first fault it meets.
The PHP manual also warns that -l will not find fatal errors that need the code to run, such as a call to a function that does not exist. A clean lint result means the file reads as valid PHP, not that every function inside it will work.
The PHP command line options page documents the -l option.
How do you know the fix worked?
The fix worked when the home page, a post page and wp-admin all load, and php -l passes on the edited file.
Reload the home page first, then open one post and the wp-admin login page. All three should load without the parse error message. If only the front end loads, the broken file is loaded only in the admin area, so read the new message and repeat the steps for the file it names.
Check the debug log as a second test. WordPress.org says that with WP_DEBUG_LOG set to true, errors are saved to debug.log in the wp-content folder. Open that file after reloading and confirm that no new parse error lines appear for the file you fixed.
Finally, turn off the debug display you used for the repair. WordPress.org recommends against leaving WP_DEBUG on for a live site, because error messages can show server paths to visitors. Set WP_DEBUG back to false once the site loads.
When should you contact your host?
Contact your host when the error names a file you never edited, when you have no file access, or when the PHP version is the cause.
A parse error in a file you never touched can mean a failed update, a damaged upload, or code written for a newer PHP version. Your host can check the server error log and restore a file from a server backup.
WordPress recommends PHP 8.3 or newer as of November 2026, and still works with PHP 7.4 or newer. Ask your host to confirm which PHP version the account runs.
Contact the host also when you cannot reach SFTP or the file manager, or when the site is on a managed plan that blocks file edits.
Give the host the full error message, the file path, and the line number, plus the last change you made. That detail lets the host restore the right file instead of guessing.
If the host confirms the code needs a newer PHP version, ask them to change it for the account. The PHP version update guide explains how to change it safely.
The WordPress PHP compatibility guide shows which PHP versions WordPress supports. Check the site again after the change.
What mistakes should you avoid?
Do not edit the live file without a copy, do not use the built-in editor for pasted code, and do not leave debug mode on.
- Edit a copy first, and keep the broken file until the site loads again, so you can compare the two versions.
- Do not paste code from a web page straight into the Theme Editor, because web pages often turn straight quotes into curly quotes.
- Do not fix only the reported line without reading the lines above it, because the real fault is often one statement earlier.
- Do not replace a whole plugin folder before you have a copy of it, because you may lose settings stored in its files.
- Do not leave
WP_DEBUGset totrueon a live site after the repair, because error text can expose server paths. - Do not guess at a fix by deleting large blocks of code you did not write, because you may remove a function the theme needs.
WordPress.org warns in its debugging guide that debug tools are meant for local testing and staging installs, not live sites. Test new code on a staging copy first when your host offers one, and run php -l on every edited file before it goes live.
The debugging guide lists the WP_DEBUG, WP_DEBUG_LOG and WP_DEBUG_DISPLAY constants.
Frequently asked questions
Can a parse error delete my posts or pages?
No, a parse error does not delete content. PHP stops reading one file before it runs, so your posts, pages and uploads stay in the database and the uploads folder. The site returns as soon as the file is valid again, because the content was never part of the broken file.
Why does the error line number point to the wrong line?
PHP reports the line where it gave up, not always the line with the mistake. A missing semicolon or bracket on an earlier line lets PHP keep reading until the next statement starts, and that is where it stops. Check the reported line and the 5 lines above it, and look at the end of each statement.
Why is wp-admin down when only one plugin is broken?
WordPress loads active plugins on every request, including admin pages, so a parse error in one active plugin file stops the whole load. Recovery Mode can pause that plugin for your session, or you can rename its folder through SFTP or your host file manager to turn it off.
Should I use the WordPress Theme Editor to fix functions.php?
No, avoid the built-in editor for this repair. The dashboard is often down anyway, and pasting code through a browser can add curly quotes. Edit the file through SFTP or your host file manager with a plain text or code editor, then check it with php -l before reloading the site.
What if the parse error appears after a plugin update I did not edit?
Rename the plugin folder to turn it off, then reinstall a clean copy of the same plugin version. A failed or damaged update can leave a broken file, and a clean reinstall replaces every file in the folder. If the clean copy fails the same way, the plugin may need a newer PHP version, so check your PHP version with your host.
Sources
- Common WordPress Errors WordPress.org
- Debugging in WordPress WordPress.org
- Recovery Mode WordPress.org
- Requirements WordPress.org
- Command line options PHP.net
- 18 Common WordPress Errors (And How To Fix Them) DreamHost
- How to Fix the Parse Error: Syntax Error, Unexpected in WordPress Rank Math
Is your product missing, or something out of date?
Tell us what to add or correct. We read every note and reply when we need a source. A message does not buy a ranking.
Thanks — we review requests within 3 business days.
