Security PHP Beginner

Hide PHP Errors From Visitors

Make sure PHP warnings and errors are never printed on your live site, where they can reveal file paths and plugin details.

Tested on WordPress 7.1 PHP 8.3 No plugin needed Updated
wp-config.php 6 lines
// Replace any existing WP_DEBUG lines in wp-config.php with these.
define( 'WP_DEBUG', false );
define( 'WP_DEBUG_DISPLAY', false );

// Many hosts show PHP errors by default, even with WP_DEBUG off.
ini_set( 'display_errors', '0' );

Where to add this

Recommended wp-config.php Above the line that says "That's all, stop editing!" in your wp-config.php file.

A PHP warning printed on your live site looks broken, and it can reveal your server’s folder structure, plugin names and versions. With WP_DEBUG off, WordPress reduces which errors are reported, but it doesn’t stop the server displaying them. This snippet does both.

How it works

WP_DEBUG set to false turns off WordPress’s debug mode, and WP_DEBUG_DISPLAY set to false tells WordPress not to print errors. ini_set( 'display_errors', '0' ) tells PHP itself not to print any errors, which covers hosts that switch display on by default.

Errors are still written to your server’s error log, where only you can see them.

Things to watch

  • Find and replace the existing WP_DEBUG line in wp-config.php rather than adding a second one; defining a constant twice causes a warning of its own.
  • When you need to debug, set WP_DEBUG to true and add define( 'WP_DEBUG_LOG', true ); to write errors to wp-content/debug.log, while keeping display off.

How to test it

View your site in a private window after triggering a known notice (for example, from a plugin you’re testing). No PHP message should appear on the page.

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only