# View the Debug Log in the Admin

> Adds a Tools > Debug Log screen that shows the last lines of wp-content/debug.log, so administrators can check errors without FTP access.

- Type: PHP
- Runs: Admin only
- Category: [Developer](https://wpide.com/library/category/developer/)
- Tags: debugging, logs, admin, tools
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/dev-debug-log-viewer/

## Code

```php
add_action( 'admin_menu', function () {
    add_management_page( 'Debug Log', 'Debug Log', 'manage_options', 'wpide-debug-log', function () {
        $lines = 200; // Number of lines to show from the end of the file.

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

        if ( defined( 'WP_DEBUG_LOG' ) && is_string( WP_DEBUG_LOG ) && '' !== WP_DEBUG_LOG ) {
            $file = WP_DEBUG_LOG;
        }

        echo '<div class="wrap"><h1>Debug Log</h1>';

        if ( ! is_readable( $file ) ) {
            echo '<p>No log file found at <code>' . esc_html( $file ) . '</code>.</p></div>';
            return;
        }

        $size   = filesize( $file );
        $handle = fopen( $file, 'rb' ); // phpcs:ignore WordPress.WP.AlternativeFunctions
        $chunk  = min( $size, 256 * 1024 );

        fseek( $handle, -$chunk, SEEK_END );
        $content = (string) fread( $handle, $chunk ); // phpcs:ignore WordPress.WP.AlternativeFunctions
        fclose( $handle ); // phpcs:ignore WordPress.WP.AlternativeFunctions

        $rows = array_slice( explode( "\n", trim( $content ) ), -$lines );

        printf( '<p><code>%1$s</code> (%2$s, last modified %3$s)</p>', esc_html( $file ), esc_html( size_format( $size ) ), esc_html( wp_date( 'Y-m-d H:i:s', filemtime( $file ) ) ) );
        echo '<pre style="max-height:70vh;overflow:auto;padding:12px;background:#1e1e1e;color:#f0f0f1;font-size:12px;line-height:1.5;white-space:pre-wrap;">' . esc_html( implode( "\n", $rows ) ) . '</pre></div>';
    } );
} );
```

## Notes

Turn on WP_DEBUG and WP_DEBUG_LOG in wp-config.php to write the log. Change $lines to show more or fewer lines.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "View the Debug Log in the Admin" 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/
