# Warn About a Public debug.log File

> Alerts administrators when WordPress writes errors to wp-content/debug.log, a file anyone can usually download and read.

- Type: PHP
- Runs: Admin only
- Category: [Security](https://wpide.com/library/category/security/)
- Tags: security, debug, notices
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/warn-public-debug-log/

## Code

```php
add_action( 'admin_notices', function () {
    if ( ! current_user_can( 'manage_options' ) ) {
        return;
    }

    $file = WP_CONTENT_DIR . '/debug.log';

    if ( ! file_exists( $file ) ) {
        return;
    }

    printf(
        '<div class="notice notice-warning"><p><strong>Public debug log found</strong> (%1$s). Visitors may be able to read it at /wp-content/debug.log. Delete it and set WP_DEBUG_LOG to a path outside the web root in wp-config.php.</p></div>',
        esc_html( size_format( (int) filesize( $file ) ) )
    );
} );
```

## Notes

Some hosts block access to .log files; the notice cannot tell, so check the URL yourself.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Warn About a Public debug.log File" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
