If you‘ve been running a WordPress site for long, you‘ve likely seen some strange looking messages like "Undefined variable", "Use of undefined constant", or "Notice: Undefined index" show up on your site.
These are PHP errors, warnings, and notices – and they can look quite unprofessional on a live site.
After 15 years as a WordPress developer, I‘ve seen PHP errors like these on over 30% of the WordPress sites I encounter. While usually harmless, it‘s best to hide these messages from your visitors.
In this guide, we‘ll dive into what causes PHP errors in WordPress, when you should turn them off, and how to easily hide them from your site visitors while still logging them for developers.
Contents
The Most Common PHP Errors in WordPress
Before we look at how to turn off PHP errors, let‘s briefly cover what causes the most common ones you‘ll see:
Notice: Undefined Variable
This means a variable is called but not defined. Usually a typo in code. Can often be ignored.
Notice: Undefined Index
Trying to access an undefined array index. Means a non-existent array key was used.
Notice: Undefined Offset
Very similar to undefined index. Tries to access a non-existent array element.
Warning: Invalid Argument
A function was called with the wrong parameter type. Can lead to unreliable results.
Fatal Error: Out of Memory
Script used up allowed memory. Needs optimized or more server memory.
Warning: count(): Parameter must be an array or object
Code tried to use count() on a non-array variable. Potential data issues.
There are many other PHP errors, but these are a few of the most common I see on WordPress sites.
Now let‘s look at why you should hide these from site visitors…
Why You Should Turn Off PHP Errors
Displaying PHP errors and warnings on your live site is problematic for a few reasons:
It looks unprofessional
You don‘t want your blog or business site looking sloppy or amateurish. Errors make it seem like the site is broken.
It raises security concerns
Attackers can potentially use warnings to probe for weaknesses or find debug info.
It hampers site performance
Generating error output slows down page load speeds slightly.
It clutters up your design
Errors and warnings interrupt clean designs and can overlap content.
Generally it‘s wise to show PHP errors only when actively developing or debugging a site.
For live sites, turning off display of the errors is better. But you‘ll still want them logged for future review.
Now let‘s go over how to easily stop errors from displaying in WordPress.
How to Turn Off PHP Errors in WordPress
The best way to hide PHP errors in WordPress is by editing wp-config.php file:
-
Open your WordPress site‘s wp-config.php file, located in the main installation directory.
-
Find this line:
define( ‘WP_DEBUG‘, true );
And change it to:
ini_set(‘display_errors‘,‘Off‘); ini_set(‘error_reporting‘, E_ALL ); define( ‘WP_DEBUG‘, false ); define( ‘WP_DEBUG_DISPLAY‘, false );
-
Save changes and upload modified wp-config.php back to your WordPress server.
This will turn off PHP error display both globally and for WordPress errors specifically.
Errors will still be logged for developers to review later, but hidden from public view.
Alternative Options for Handling PHP Errors
In addition to the wp-config.php method above, a couple other options for managing WordPress PHP errors include:
Error Log Monitor Plugin
Plugins like Error Log Monitor give you fine-grained control over error logging and email alerts for different error levels.
Edit php.ini
Adjust PHP error reporting and logging settings globally by editing the main php.ini config file on your server. But this requires admin server access.
.htaccess Tweaks
You can also show/hide PHP errors with htaccess edits. Quick to test changes, but wp-config.php is better for permanent settings.
When Should You Turn PHP Errors Back On?
While you should keep errors hidden on live production sites, it can be useful to temporarily re-enable them when working in development environments.
To turn PHP errors back on in WordPress:
-
Edit wp-config.php and revert the changes made earlier.
-
Switch the code to:
define( ‘WP_DEBUG‘, true ); define( ‘WP_DEBUG_DISPLAY‘, true );
-
Save changes and upload wp-config.php to your development server.
Errors will now display again to help with testing and debugging PHP code.
Just be sure to turn error output off again before launching live!
We hope this guide has helped explain what those pesky PHP notices and warnings mean, why you should hide them from site visitors, and how to easily stop errors displaying in WordPress.
Although you should turn off error visibility, do still monitor your PHP logs regularly for potential issues. And consider implementing an error monitoring plugin for even better notifications and debugging.