wp_print_scripts

函式
wp_print_scripts ( $handles = false )
引數
  • (string|bool|array) $handles Optional. Scripts to be printed. Default 'false'.
    Required:
    Default: false
返回值
  • (string[]) On success, an array of handles of processed WP_Dependencies items; otherwise, an empty array.
相關
  • WP_Scripts::do_item()
定義位置
相關方法
wp_print_script_tagwp_print_head_scriptswp_print_footer_scriptswp_playlist_scriptswp_scripts
引入
2.1.0
棄用
-

wp_print_scripts: 這個動作用來列印所有為頁面排隊的指令碼。它用於確保所有必要的指令碼都包含在頁面中。

列印文件頭部的$handles佇列中的指令碼。

由admin-header.php和{@see ‘wp_head’}掛鉤呼叫。由於它在每次載入頁面時都會被wp_head呼叫,因此除非明確傳遞指令碼名稱,否則該函式不會例項化WP_Scripts物件。如果存在的話,會使用已經例項化的$wp_scripts全域性。使用提供的{@see ‘wp_print_scripts’}鉤子來註冊/獲取新的指令碼。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function wp_print_scripts( $handles = false ) {
global $wp_scripts;
/**
* 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__ );
if ( ! ( $wp_scripts instanceof WP_Scripts ) ) {
if ( ! $handles ) {
return array(); // No need to instantiate if nothing is there.
}
}
return wp_scripts()->do_items( $handles );
}
function wp_print_scripts( $handles = false ) { global $wp_scripts; /** * 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__ ); if ( ! ( $wp_scripts instanceof WP_Scripts ) ) { if ( ! $handles ) { return array(); // No need to instantiate if nothing is there. } } return wp_scripts()->do_items( $handles ); }
function wp_print_scripts( $handles = false ) {
	global $wp_scripts;

	/**
	 * 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__ );

	if ( ! ( $wp_scripts instanceof WP_Scripts ) ) {
		if ( ! $handles ) {
			return array(); // No need to instantiate if nothing is there.
		}
	}

	return wp_scripts()->do_items( $handles );
}

常見問題

FAQs
檢視更多 >