Halloween Sale 15% off Ends in See the plans
PHP

List Enqueued Scripts and Styles in the Page Source

Prints an HTML comment at the bottom of each page, visible to administrators, listing every script and stylesheet handle loaded and its source, to find what to optimize.

Don’t have WPIDE yet? Install it on your site

Code

add_action( 'wp_print_footer_scripts', function () {
    if ( ! current_user_can( 'manage_options' ) ) {
        return;
    }

    $lines = array( 'Enqueued assets' );

    foreach ( array( 'scripts' => wp_scripts(), 'styles' => wp_styles() ) as $type => $deps ) {
        $lines[] = strtoupper( $type ) . ':';

        foreach ( $deps->done as $handle ) {
            $src     = isset( $deps->registered[ $handle ] ) ? (string) $deps->registered[ $handle ]->src : '';
            $lines[] = '  ' . $handle . ( $src ? ' => ' . $src : ' (inline/alias)' );
        }
    }

    echo "\n<!--\n" . esc_html( str_replace( '--', '- -', implode( "\n", $lines ) ) ) . "\n-->\n";
}, 999 );

Notes

View the page source and look for "Enqueued assets" near the end.

How to add this snippet

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.