Category: WordPress
In WordPress development, especially when using third-party plugins or custom themes, it's not uncommon to see PHP notices or warnings showing up either on the screen or filling up your logs. While these messages are helpful during development, in a production environment, they can clutter your logs, increase disk usage, and even confuse non-technical users if they're displayed on the frontend.
Fortunately, there's a simple way to suppress these notices and warnings using a Must-Use (MU) Plugin. In this article, we’ll show you how to set that up and explain why it’s a good idea in many scenarios.
What Are Must-Use Plugins?
MU Plugins, or Must-Use plugins, are a special type of plugin in WordPress that are automatically loaded by WordPress on every page load. These plugins reside in the wp-content/mu-plugins/ directory and cannot be deactivated from the admin dashboard like regular plugins.
Because they’re always active, MU plugins are ideal for critical functionality that you don’t want anyone accidentally disabling—like security tweaks, performance fixes, or in this case, silencing PHP warnings and notices.
Why Disable PHP Notices and Warnings?
While notices and warnings don’t break your site, they do serve as alerts that something might not be quite right in your code—or in the code of a plugin you’re using.
However, in a live environment, they can become more of a nuisance than a help. Here’s why you might want to suppress them:
Cleaner Logs: If a specific warning or notice is triggered repeatedly, your error log can grow very quickly. This can eat up disk space and make it harder to find real issues.
Performance: Writing to log files has a performance cost. By cutting out unnecessary messages, you reduce I/O operations.
Better User Experience: If error reporting is enabled, notices might appear on the frontend, creating confusion or making your site look unprofessional.
Security: Some warnings might reveal file paths or sensitive server info that you don’t want exposed.
Create the MU Plugin to Suppress Warnings and Notices
Let’s create a small plugin to disable those noisy PHP messages. Save the following code into a file called 000-orbisius-disable-some-errors.php and place it in your wp-content/mu-plugins/ folder.
<?php
/**
* Plugin Name: Disable PHP Notices and Warnings
* Description: Suppresses PHP notices and warnings across the WordPress site.
* Author: Svetoslav Marinov | https://orbisius.com
* Author URI: https://orbisius.com/7998
* License: GPL2
* Version: 1.0.0
*/
// Only affect frontend and admin, not CLI or REST API debug tools.
if (php_sapi_name() != 'cli') {
// Set error reporting to ignore notices and warnings.
error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING & ~E_DEPRECATED & ~E_STRICT);
// Optionally disable display of errors to users (recommended in production)
// we may not need this.
// @ini_set('display_errors', '0');
}
A few notes:
- We avoid touching CLI environments so tools like WP-CLI and REST debugging remain functional.
- The use of
000-
at the beginning of the filename ensures this plugin is loaded first. - The
error_reporting
setting is scoped to the runtime, so this won’t change server-wide behavior—just for the WordPress requests.
You can also try to package code using tools like WordPress Plugin Generator from WPSandbox.net
Final Thoughts
While it’s always best to fix the root causes of warnings and notices during development, muting them in production can offer a more stable and clean environment. Using a lightweight MU plugin like this is an elegant way to reduce log noise, improve performance slightly, and prevent unintentional information disclosure.