Troubleshooting
WordPress PHP Not Working: Causes and How to Fix It

Short answer
PHP stops working on WordPress when the server has no working PHP handler, the PHP version is wrong, a fatal error stops execution, or code sits where WordPress never runs it. Match your symptom first: raw code or downloads point to the server, while blank screens point to a plugin, theme or snippet error.
Key takeaways
- Raw PHP code or file downloads mean the server handler is broken.
- Bad AddHandler lines in htaccess often cause PHP downloads after a migration.
- White screens and critical errors mean PHP runs but your code fails.
- WordPress never runs PHP typed into post content; use a shortcode instead.
- Check the PHP version and required extensions in Site Health.
- Use the server error log when debug.log stays empty.
Why is PHP not working on my WordPress site?
PHP usually stops working on WordPress because the server is not passing PHP files to the PHP interpreter, the PHP version is wrong, a fatal error is stopping execution, or the code sits somewhere PHP is never run.
WordPress itself is a PHP application, as covered in is WordPress written in PHP. So when people say PHP is not working, they usually mean one of four different things:
- The browser shows raw PHP code, or downloads a
.phpfile instead of showing a page. - The site shows a blank white page or a critical error message.
- A custom PHP snippet you added does nothing.
- PHP code pasted into a post or page prints as plain text.
Each symptom has a different cause. The table below maps them quickly, and the sections after it walk through each fix.
| Symptom | Most likely cause | First fix to try |
|---|---|---|
| Raw PHP code shows in the browser | PHP handler missing or broken on the server | Check the PHP handler in your hosting panel |
| Browser downloads index.php | Wrong handler line in .htaccess | Remove custom AddHandler lines |
| White screen or critical error | Fatal PHP error | Turn on WP_DEBUG and read the log |
| Snippet in functions.php does nothing | Wrong hook, wrong file or child theme not active | Check the active theme and hook |
| PHP in a post shows as text | WordPress does not run PHP in content | Use a shortcode or snippet plugin |
| Site broke after a PHP upgrade | Old plugin or theme not compatible | Switch back, then update the extension |
Why does my browser show PHP code instead of the page?
If you see lines starting with <?php in the browser, the web server is sending the file as plain text because no PHP handler is attached to .php files.
This happens on the server, not inside WordPress. Common reasons:
- PHP is not installed on a local server or a fresh VPS.
- The PHP-FPM service stopped, so Nginx or Apache has nothing to pass requests to.
- The Nginx config lacks a
location ~ \.php$block, so PHP files are served as static files. - Apache's PHP module is disabled after a system update.
On shared hosting, open your control panel and look for a PHP version or MultiPHP Manager screen. Pick a supported version and save it, even if it already looks correct. That re-applies the handler.
On a VPS, check that PHP-FPM is running with your system's service manager. Then confirm the web server config passes PHP files to it. The Nginx WordPress recipe and the PHP installation manual show the expected setup.
Never leave a server in this state for long. Raw PHP output can expose database passwords from wp-config.php if that file is ever served directly.
Why does my browser download PHP files instead of running them?
A download prompt for index.php almost always means a bad handler line in your .htaccess file tells Apache to treat PHP as a file type it cannot run.
This often appears after a host migration or after a plugin or old tutorial added a line such as AddHandler or AddType for a PHP version the new server does not have.
To fix it:
- Connect by FTP or the host's file manager.
- Download a copy of
.htaccessfrom the WordPress root as a backup. - Open it and look for lines that mention
AddHandler,AddTypeorSetHandlerwith a PHP version name. - Remove those lines, save the file and reload the site.
- If the site works, set the PHP version through the hosting panel instead, which writes the correct handler.
If you are not sure what belongs in the file, replace it with the default WordPress rules from the htaccess page on WordPress.org. Then resave Settings > Permalinks to rebuild them.
Clear your browser cache after the fix. Browsers sometimes remember the download response.
What if WordPress shows a white screen or critical error?
A white screen or a There has been a critical error on this website message means PHP is running but hit a fatal error, usually from a plugin, theme or snippet.
Here PHP works fine, but your code is failing. Start by turning on debugging, as shown in how to enable debug mode in WordPress. Add these lines to wp-config.php above the stop editing comment:
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );
Reload the broken page, then open wp-content/debug.log. The last lines name the file and line number that failed. Our guide on how to read the WordPress debug log explains each part of an entry.
Typical fatal errors include:
- Call to undefined function, often a plugin that depends on another plugin you removed.
- Allowed memory size exhausted, fixed by raising the limit as explained in how to increase the PHP memory limit.
- Syntax error, unexpected, which points to a typo in a snippet you just added.
For a full walkthrough of these screens, see how to fix the WordPress white screen of death.
Why is my PHP code in functions.php not doing anything?
Code in functions.php that has no effect is usually in the wrong theme, attached to the wrong hook, or running too late or too early to change anything.
Check these points in order:
- Is that theme active? Edits to a parent theme do nothing if a child theme is active, and the other way round. Check Appearance > Themes.
- Is it a block theme? Many block themes have a small
functions.php, but it still loads. Make sure you edited the theme that WordPress shows as active. - Is the hook right? For example, enqueueing scripts must use
wp_enqueue_scripts, notinit. The Plugin API hooks reference lists when each runs. - Is the priority right? If another plugin runs the same filter later, it can overwrite your change. Try a higher priority number.
- Is caching hiding the change? Clear page cache, server cache and any CDN cache before testing.
A code snippet plugin keeps snippets separate from the theme, so they survive theme updates. That is safer than editing theme files directly.
Why does PHP code in a post or page show as text?
WordPress never runs PHP typed into post or page content, by design, because letting editors run server code would be a serious security risk.
If you paste <?php echo date('Y'); ?> into a Paragraph or Custom HTML block, WordPress stores and prints it as text. That is expected behaviour.
To run PHP output inside content, use one of these instead:
- Register a shortcode in a plugin or snippet, then place the shortcode in a Shortcode block. The Shortcode API shows the pattern.
- Build a custom block if the output needs settings in the editor.
- Use a code snippet plugin that offers shortcode output.
Avoid old PHP in posts plugins that execute raw code from content. Many are abandoned, and they let anyone with editor access run code on your server.
Could the PHP version be the problem?
Yes, a PHP version that is too old for WordPress or too new for an old plugin is a very common cause of PHP failures after hosting changes or upgrades.
WordPress publishes its current recommendation on the WordPress requirements page. Older plugins may use functions removed in newer PHP releases, which then cause fatal errors.
First, confirm what you are running. Tools > Site Health > Info > Server shows the PHP version, or see how to check the PHP version on your host.
If the site broke right after an upgrade:
- Switch back to the previous PHP version in your hosting panel.
- Update all plugins and themes on a staging copy.
- Read the debug log for deprecated or removed function messages.
- Upgrade PHP again once the log is clean.
Our guide to a site broken after a PHP update covers this rollback in detail.
Could missing PHP extensions cause it?
Yes, WordPress and many plugins need PHP extensions such as mysqli, curl, mbstring, xml and zip, and a missing one causes errors that look like PHP is broken.
The most serious is the database extension. Without mysqli, WordPress shows Your PHP installation appears to be missing the MySQL extension which is required by WordPress.
Site Health often flags missing optional modules under Tools > Site Health > Status. On shared hosting, you can usually enable extensions from the PHP options screen. On a VPS, install the matching package for your PHP version and restart PHP-FPM.
Image errors, failed updates and broken imports are often the first signs. For example, a missing zip extension can stop plugin updates from unpacking.
How do I find the real error when nothing is logged?
When the screen is blank and debug.log stays empty, check the server's PHP error log, because some fatal errors happen before WordPress can write its own log.
Your host usually provides error logs in the control panel. See how to check PHP error logs for where common hosts keep them.
You can also test PHP directly. Create a file called test.php in the site root containing <?php phpinfo();. Visit it in a browser:
- If you see the PHP info page, PHP works and the problem is inside WordPress.
- If you see the raw code or a download, the server handler is broken.
Delete test.php right after. It exposes server details that attackers can use.
How do I stop PHP problems from coming back?
Keep PHP on a supported version, test upgrades on staging, keep custom code in a snippet plugin or child theme, and remove plugins that are no longer maintained.
A short checklist helps:
- Note your PHP version and active plugins before any hosting change.
- Use staging for PHP upgrades and big plugin updates.
- Keep
WP_DEBUG_LOGoff on live sites once fixed, so logs do not grow forever. - Remove abandoned plugins, which are the usual source of incompatibility errors.
- Take a backup before editing
.htaccess,wp-config.phpor theme files.
If you still cannot fix it, contact your host with the exact symptom, the time it started and any log lines. Hosts can see server logs you cannot, which saves time.
Frequently asked questions
Why does my WordPress site show PHP code instead of the page?
The web server has no working PHP handler for PHP files, so it sends them as plain text. Re-select your PHP version in the hosting panel, check that PHP-FPM is running on a VPS, and confirm the server config passes PHP files to the interpreter.
Can I run PHP code inside a WordPress post?
Not directly. WordPress prints PHP typed into post content as text for security reasons. Register a shortcode in a snippet plugin or child theme instead, then place that shortcode in a Shortcode block where you want the output to appear.
Why does my site download index.php instead of loading?
Usually a leftover AddHandler or AddType line in the htaccess file points to a PHP version the server does not have. Back up the file, remove those lines, reload the site, and then set the PHP version through your hosting control panel.
How do I check if PHP works on my server?
Create a small test file in the site root that calls the phpinfo function, then visit it in a browser. If the PHP info page appears, PHP works and the fault is inside WordPress. Delete the test file immediately afterwards because it exposes server details.
Can the wrong PHP version break WordPress?
Yes. Very old PHP versions do not meet WordPress requirements, and very new versions can break old plugins that use removed functions. If the site broke after an upgrade, switch back, update extensions on staging, and upgrade again once the debug log is clean.
Sources
- Server requirements WordPress.org
- Debugging in WordPress WordPress Developer Resources
- Installation and configuration PHP Manual
- Hooks WordPress Developer Resources
- Shortcodes WordPress Developer Resources
- WordPress recipe NGINX
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.
Related guides
About the editors
Researched from the primary sources listed above and checked against our editorial rules before publishing.


