打印$ handles队列中文档头中的脚本。
原型
wp_print_scripts( string|bool|array $handles = false )
描述
由admin-header.php和’wp_head’钩子调用。由于wp_head在每次加载页面时都会调用它,因此除非显式传递脚本名称,否则该函数不会实例化WP_Scripts对象。如果存在,则使用已经实例化的$ wp_scripts全局。使用提供的’wp_print_scripts’钩子来注册/排队新脚本。
参考:
- WP_Scripts::do_items()
参数
$handles
(string|bool|array)
(Optional)
要打印的脚本。默认为’false’。
返回值
(array)
成功时,处理过的数组
源文件
路径:wp-includes/functions.wp-scripts.php
<?php
...
function wp_print_scripts( $handles = false ) {
/**
* Fires before scripts in the $handles queue are printed.
*
* @since 2.1.0
*/
do_action( 'wp_print_scripts' );
if ( '' === $handles ) { // for wp_head
$handles = false;
}
_wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
global $wp_scripts;
if ( ! ( $wp_scripts instanceof WP_Scripts ) ) {
if ( ! $handles ) {
return array(); // No need to instantiate if nothing is there.
}
}
return wp_scripts()->do_items( $handles );
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/wp_print_scripts/