WordPress.org

Ready to get started?Download WordPress

Ideas

Function to display an array of all enqueued scripts/styles

  1. JohnnyPea
    Member

    12345

    I would like to have a function which will display all enqueued scripts/styles.

    I need this to find out which scripts/styles have been added by the plugins or the theme.

    Posted: 3 years ago #
  2. Mark / t31os
    Moderator

    12345

    Might try printing out the $wp_styles and $wp_scripts variables... :)

    Posted: 3 years ago #
  3. adaldesign
    Member

    To use Mark's solution, try the following in a template file:

    <?php global $wp_scripts; var_dump($wp_scripts); ?>

    However here's another solution I prefer strongly (taken from this WordPress Answers post), paste it in your functions.php:

    function wpa54064_inspect_scripts() {
        global $wp_scripts;
        foreach( $wp_scripts->queue as $handle ) :
            echo $handle . ' | ';
        endforeach;
    }
    add_action( 'wp_print_scripts', 'wpa54064_inspect_scripts' );

    Then look at the HTML page source to see the list (near the scripts in the header).

    Posted: 1 year ago #
  4. Like @Mark and @adaldesign said, print out each variable you want, whether $wp_scripts or $wp_styles.
    To slip it into a template file, it has to be after wp_head() so in my header.php file I have this chunk:

    <?php
      wp_head();
      global $wp_scripts, $wp_styles;
      //var_dump( $wp_scripts );
      //var_dump( $wp_styles );
    ?>

    Then you can uncomment the one you want to see

    Posted: 11 months ago #

RSS feed for this topic

Reply

You must log in to post.

  • Rating

    12345
    7 Votes
  • Status

    This idea has been implemented