
How to Turn Off PHP Errors in WordPress
Introduction
If you manage a WordPress site, you may have seen strange error messages. These are called PHP errors. They show up on your screen and can confuse your visitors. They also make your website look unprofessional and messy.
PHP errors are helpful in development. But they should never appear on a live website. If search engines or customers see these, it can harm your SEO and trust.
These errors often include:
- Notices
- Warnings
- Deprecated messages
- Fatal errors
In this guide, we’ll show you how to turn them off. You’ll learn the safest methods to hide PHP errors. You’ll also discover how to keep logs for developers, without showing anything to users.
By the end of this article, your site will look clean and professional. Whether you’re a site owner, admin, or developer, this guide will help you.
Why You See PHP Errors in WordPress
WordPress runs on PHP. When PHP finds a problem, it sends a message. These messages help developers fix bugs. But on a live site, they are not useful to users.
You might see messages like:
- “Notice: Undefined variable”
- “Warning: Invalid argument supplied for foreach()”
- “Deprecated: Function xyz() is deprecated”
These errors appear because:
- A plugin or theme has coding issues
- Your hosting is set to show all errors
- WordPress is in debug mode
- You are using an outdated PHP version
In development, showing errors is good. It helps you catch problems early. But on a production site, errors should be hidden.
Here’s why:
- They confuse visitors
- They expose your site’s file paths
- They lower trust and credibility
- They hurt your SEO rankings
For example, if your website shows a PHP warning on the homepage, Google may index that error. This can damage your search performance.
So what’s the right thing to do?
You should log errors quietly, but never show them on the front end. WordPress makes this easy using settings in the wp-config.php file, MU-plugins, and runtime tweaks. We’ll explore each method in the next sections.
Before you start, make sure you have access to your WordPress files. You may need FTP or file manager from your hosting panel.
Methods to Disable PHP Errors in WordPress (With Use Cases)
WordPress gives you several ways to hide PHP errors. Each method works best in different situations. Below are the three most reliable ways to do it, along with the issues each one solves.
Disable PHP Errors via wp-config.php (Your First Line of Defense)
The wp-config.php file is the heart of your WordPress site. It controls many important settings, including PHP error display. You can turn off PHP errors here quickly and safely.
Many users don’t realize that one small change can hide all error messages. But it’s important to do it the right way. If done wrong, your site may still show errors or even stop working.
Let’s walk through the correct steps.
What is wp-config.php?
This file is located in your site’s root folder. It contains your database details, secret keys, and core WordPress settings. It loads every time someone visits your site.
By editing this file, you can control how WordPress handles PHP errors. This is useful when you want to hide errors from visitors but still keep logs for developers.
How to Edit wp-config.php Safely
Before you make changes, create a full backup of your site. Mistakes in this file can cause your site to go down.
To access it, use:
- File Manager in your hosting panel
- An FTP tool like FileZilla
- The command line (for advanced users)
Once inside your WordPress directory, open wp-config.php using a code editor.
Now, find the line:
/* That’s all, stop editing! Happy publishing. */
Important: Add new lines above this comment.
Recommended Code to Disable PHP Errors
Here’s what you should add:
define(‘WP_DEBUG’, false);
define(‘WP_DEBUG_DISPLAY’, false);
define(‘WP_DEBUG_LOG’, true);
Let’s break this down:
- WP_DEBUG turns off all debug mode settings.
- WP_DEBUG_DISPLAY stops errors from showing on the screen.
- WP_DEBUG_LOG keeps a log of errors in a file (good for developers).
You’ll find the error log in wp-content/debug.log.
Why This Method Is Recommended
This method is easy and safe. It works on almost all WordPress setups. You don’t need extra plugins or coding skills.
By using this method, you:
- Hide PHP notices and warnings from visitors
- Keep a log of errors for review
- Improve your site’s look and feel
- Avoid leaking sensitive information
Advanced Methods to Hide PHP Errors in WordPress
Sometimes editing wp-config.php is not enough. You may still see PHP warnings or notices. Some themes or plugins override global settings. In such cases, you need more control.
This part covers two advanced methods:
- Using ini_set() and error_reporting() in your code
- Creating an MU-plugin to disable errors sitewide
These methods are ideal for developers or users managing multiple sites.
Method 1: Use ini_set() and error_reporting() in Code
This method gives you dynamic control over error reporting. You can add it to your theme’s functions.php file or a custom plugin.
It’s useful when:
- wp-config.php edits don’t work due to hosting rules
- You want to suppress only certain error types
- Plugins or themes force PHP errors on-screen
How to Do It:
Add this code to your theme’s functions.php or in a custom plugin:
ini_set(‘display_errors’, ‘0’);
error_reporting(E_ALL & ~E_NOTICE);
This hides PHP notices while still reporting important errors.
To suppress deprecated warnings as well, use:
error_reporting(E_ALL & ~E_DEPRECATED & ~E_NOTICE);
What Each Line Does:
- ini_set(‘display_errors’, ‘0’); – Hides errors from the screen
- error_reporting(…) – Tells PHP which errors to log or ignore
You can fine-tune it depending on what you want to hide.
When to Use This:
- Your hosting environment limits wp-config.php edits
- You want to control which error levels are shown
- You are debugging a plugin but hiding errors from users
Method 2: Use an MU-Plugin to Hide PHP Errors Globally
MU stands for “Must-Use.” MU-plugins are always active. WordPress loads them before any theme or regular plugin. This makes them perfect for setting global options, like hiding PHP errors.
Why Use an MU-Plugin?
- Works across all themes and plugins
- Can’t be turned off from the admin area
- Perfect for agencies managing client sites
- Great for multisite WordPress installations
How to Create an MU-Plugin:
- Go to your WordPress installation folder
- Navigate to: wp-content/mu-plugins/
(If the folder doesn’t exist, create it) - Inside, create a file named disable-errors.php
- Add the following code:
<?php
ini_set(‘display_errors’, ‘0’);
define(‘WP_DEBUG’, false);
define(‘WP_DEBUG_DISPLAY’, false);
Save the file. That’s it. Errors are now suppressed across the entire site.
Important Notes:
- MU-plugins don’t show up in the Plugins menu
- They run before any theme or normal plugin
- Ideal for forced, non-editable site rules
Troubleshooting and Fixes
Sometimes, even after disabling PHP errors using the methods described earlier, error messages still appear. This can be frustrating, especially on live sites. The reason might be improper settings, plugin conflicts, or caching issues.
In this part, we’ll explore common problems users face when trying to turn off PHP errors and how to fix them effectively.
Check for Caching Issues
One of the most common causes of PHP errors still appearing is server or browser caching. If your site uses a caching plugin or server-level caching, changes to wp-config.php or MU-plugins might not reflect right away.
In some cases, hosting environments like managed WordPress hosting use OPcache. This cache stores compiled PHP scripts to speed up performance. But it also delays the effect of recent changes.
To fix this, you should:
- Clear all cache from your WordPress caching plugin.
- Clear your browser cache.
- If your host uses OPcache, ask them to flush it.
- Add opcache_reset(); to your code temporarily to force reset.
After clearing all caches, check again to see if the errors still appear.
Make Sure wp-config.php Settings Are in the Right Place
If you placed the error settings in the wrong part of the wp-config.php file, WordPress may ignore them. This is a common mistake.
You must place all debug-related lines above the line that says:
/* That’s all, stop editing! Happy publishing. */
For example, this block should go above that line:
define(‘WP_DEBUG’, false);
define(‘WP_DEBUG_DISPLAY’, false);
define(‘WP_DEBUG_LOG’, true);
If placed below, WordPress won’t use the settings, and errors may still display.
Identify Plugin or Theme Conflicts
Sometimes, themes or plugins have their own settings that force PHP errors to show. Even if you disable errors in wp-config.php, the plugin or theme can override it using ini_set() or error_reporting().
To find the issue:
- Deactivate all plugins.
- Switch to a default WordPress theme like Twenty Twenty-Four.
- Check if the errors disappear.
Then, reactivate your plugins one by one to find the one causing the problem. Once you find it, check its documentation or contact the plugin developer.
Double-Check Your MU-Plugin Setup
If you’re using an MU-plugin to hide PHP errors, it must be set up correctly. Sometimes, users put the plugin file in the wrong folder or use the wrong file format.
Here’s what to check:
- The file should be in wp-content/mu-plugins/.
- It must have a .php extension.
- The code inside must not have syntax errors.
Even one small error in the plugin can cause it to silently fail. If you’re unsure, remove the plugin and test again.
Your Hosting Provider Might Be Overriding Settings
Some hosting providers control how PHP errors are displayed. They might enforce their own php.ini settings, which override your WordPress configurations.
If all else fails, contact your hosting support. Ask them if they allow you to disable PHP error display and how to do it on their server.
They might suggest:
- Adding custom settings to .htaccess or a local php.ini file.
- Disabling error display from the hosting control panel.
Keep an Eye on debug.log
Even after you hide errors from users, WordPress may still log them if WP_DEBUG_LOG is enabled. Check wp-content/debug.log to review hidden errors. This helps you track issues while keeping your site clean.
Common Mistakes to Avoid
Many WordPress users try to hide PHP errors but make small mistakes. These mistakes may cause errors to keep showing even after changes are made. Below are the most common mistakes and how to avoid them.
Mistake 1: WP_DEBUG is Still Turned On
One of the biggest mistakes is leaving WP_DEBUG set to true. If it is enabled, WordPress will continue to show PHP errors on the site.
How to avoid this:
Make sure the following line is added to your wp-config.php file:
define(‘WP_DEBUG’, false);
This will turn off the debug mode and stop PHP error messages from appearing.
Mistake 2: Wrong Placement of Code in wp-config.php
Some users place debug settings in the wrong place inside wp-config.php. If the code is placed after the comment line that says “stop editing,” WordPress will ignore it.
How to avoid this:
Always place your debug settings above this line:
/* That’s all, stop editing! Happy publishing. */
Any code written below this line may not work at all.
Mistake 3: Forgetting to Clear Cache
Even after changing your settings, errors might still appear. This usually happens because of browser or plugin cache. Cached pages may show old error messages.
How to avoid this:
After you update your error settings:
- Clear your WordPress cache using your caching plugin.
- Clear your browser cache.
- If your server uses OPcache, ask your host to flush it.
This will help you see the latest version of your site.
Mistake 4: Ignoring the debug.log File
Some users hide errors from the screen but forget to check the error log. Errors may still be happening in the background. This can lead to larger problems later.
How to avoid this:
If you use this setting in wp-config.php:
define(‘WP_DEBUG_LOG’, true);
Then WordPress saves all errors in a file called debug.log, located in the wp-content folder. Check this file often, especially after installing new plugins or updates.
Mistake 5: Using Incorrect Code Formatting
Copying code from websites can sometimes lead to format issues. For example, smart quotes or missing semicolons may break your site.
How to avoid this:
- Always type code manually or use a plain text editor.
- Avoid using quotation marks like “ ” or ‘ ’. Use ‘ or ” instead.
- Check for missing semicolons at the end of each line.
By avoiding these simple mistakes, you can make sure PHP errors are hidden properly. Your WordPress site will look more professional, and your visitors will have a better experience.
Conclusion
Managing PHP errors, the right way helps keep your WordPress site clean, fast, and user-friendly. Whether you’re running a personal blog or a business website, handling errors behind the scenes protects both your visitors and your reputation. If you’re unsure how to apply these methods or something still isn’t working as expected, don’t worry. Our team at 24x7WP Support is here to help. We offer expert WordPress assistance any time, day or night. From technical fixes to full website management, we’ve got you covered. Don’t let PHP errors slow you down—reach out to 24x7WP Support and let us handle the technical side while you focus on growing your site.
Looking for more WordPress help? Subscribe to our YouTube Channel for expert video tutorials. Join us on Twitter and Facebook for updates, tips, and insights.