admin管理员组文章数量:1415467
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 badges1 Answer
Reset to default 0In 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
}
}
本文标签: plugin developmentHow do I ensure I can loop through every enqueued script and CSS
版权声明:本文标题:plugin development - How do I ensure I can loop through every enqueued script and CSS? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745184702a2646628.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论