# Send PHP Values to the Browser Console

> Adds a wpide_console() helper that prints any PHP variable to the browser's developer console for administrators, so you can inspect data without breaking the page layout.

- Type: PHP
- Runs: Run everywhere
- Category: [Developer](https://wpide.com/library/category/developer/)
- Tags: debugging, helper, console
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/debug-console-log-helper/

## Code

```php
if ( ! function_exists( 'wpide_console' ) ) {
    function wpide_console( $value, $label = '' ) {
        if ( ! current_user_can( 'manage_options' ) ) {
            return;
        }
        $GLOBALS['wpide_console_queue'][] = array( (string) $label, $value );
    }
}

$wpide_console_flush = function () {
    if ( empty( $GLOBALS['wpide_console_queue'] ) ) {
        return;
    }
    echo '<script>';
    foreach ( $GLOBALS['wpide_console_queue'] as $entry ) {
        list( $label, $value ) = $entry;
        printf( 'console.log(%s, %s);', wp_json_encode( $label ? "PHP: $label" : 'PHP:' ), wp_json_encode( $value, JSON_PARTIAL_OUTPUT_ON_ERROR | JSON_HEX_TAG | JSON_HEX_AMP ) );
    }
    echo '</script>';
    $GLOBALS['wpide_console_queue'] = array();
};

add_action( 'wp_footer', $wpide_console_flush, PHP_INT_MAX );
add_action( 'admin_footer', $wpide_console_flush, PHP_INT_MAX );
```

## Notes

Example wpide_console( $post, 'Current post' ); values are queued and printed in the footer of front-end and admin pages.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Send PHP Values to the Browser Console" 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/
