plugin development - How do I ensure I can loop through every enqueued script and CSS?

I'm on a bit of an efficiency drive. To this end, I would like to check all the scripts and CSS that get enqueued o

I'm on a bit of an efficiency drive. To this end, I would like to check all the scripts and CSS that get enqueued on my multisite setup. I plan to check that they are offloaded to public CDNs if available or some other private static site if I have set that up, while also ensuring there are no duplicates.

Where I am currently stuck (aside from wondering if the extra work actually will save load times at all) is what hook I can use to make sure all the enqueing is done when my script kicks in.

What hook or filter should I use for this purpose?

(Feel free to educate me and any future searchers about anything else I/we should know when attempting this).

I'm on a bit of an efficiency drive. To this end, I would like to check all the scripts and CSS that get enqueued on my multisite setup. I plan to check that they are offloaded to public CDNs if available or some other private static site if I have set that up, while also ensuring there are no duplicates.

Where I am currently stuck (aside from wondering if the extra work actually will save load times at all) is what hook I can use to make sure all the enqueing is done when my script kicks in.

What hook or filter should I use for this purpose?

(Feel free to educate me and any future searchers about anything else I/we should know when attempting this).

Share Improve this question asked Sep 4, 2019 at 20:47 Matthew Brown aka Lord MattMatthew Brown aka Lord Matt 1,0683 gold badges13 silver badges34 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

In terms of the basics, I have learned that there are two actions to hook - wp_print_scripts and wp_print_styles which I understand are called just before they are then added to the header.

add_action( 'wp_print_scripts', 'my_list_scripts' );
function my_list_scripts() {
    global $wp_scripts;
    $enqueued_scripts = array();
    foreach( $wp_scripts->queue as $handle ) {
        // do something clever
    }

}
add_action( 'wp_print_styles', 'my_list_styles' );
function my_list_styles() {
    global $wp_styles;
    $enqueued_styles = array();
    foreach( $wp_styles->queue as $handle ) {
        // do something clever
    }
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745184702a4615581.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信