Turn on WordPress debug logging, hide errors from visitors and write the log to a folder that can't be opened in a browser.
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_DISPLAY', false );
@ini_set( 'display_errors', '0' );
// One folder above the site root, so the log can't be opened in a browser.
define( 'WP_DEBUG_LOG', dirname( __DIR__ ) . '/logs/wp-errors.log' );
Turning on WP_DEBUG_LOG the usual way writes errors to wp-content/debug.log, which anyone can download if they guess the address. Logs can contain file paths, database details and other information attackers find useful. This setup keeps the log out of reach.
WP_DEBUG turns on error reporting, and WP_DEBUG_DISPLAY with display_errors set to 0 stops errors appearing on pages.
Setting WP_DEBUG_LOG to a file path, instead of true, tells WordPress where to write. dirname( __DIR__ ) is the folder above the one containing wp-config.php, which on most hosts is outside the public web root.
logs folder first and make sure PHP can write to it.Add trigger_error( 'test', E_USER_NOTICE ); to a snippet, load a page and check the log file. The page itself should show no error.