wp_register_script

函式
wp_register_script ( $handle, $src, $deps = array(), $ver = false, $in_footer = false )
引數
  • (string) $handle Name of the script. Should be unique.
    Required:
  • (string|false) $src Full URL of the script, or path of the script relative to the WordPress root directory. If source is set to false, script is an alias of other scripts it depends on.
    Required:
  • (string[]) $deps Optional. An array of registered script handles this script depends on. Default empty array.
    Required:
    Default: array()
  • (string|bool|null) $ver Optional. String specifying script version number, if it has one, which is added to the URL as a query string for cache busting purposes. If version is set to false, a version number is automatically added equal to current installed WordPress version. If set to null, no version is added.
    Required:
    Default: false
  • (bool) $in_footer Optional. Whether to enqueue the script before `</body>` instead of in the `<head>`. Default 'false'.
    Required:
    Default: false
返回值
  • (bool) Whether the script has been registered. True on success, false on failure.
相關
  • WP_Dependencies::add()
  • WP_Dependencies::add_data()
定義位置
相關方法
wp_deregister_scriptwp_register_tinymce_scriptswp_register_stylewp_print_scriptswp_deregister_style
引入
2.1.0
棄用
-

wp_register_script: 這個函式用來向WordPress註冊一個指令碼。它接受幾個引數,包括指令碼的名稱、源URL、依賴性、版本,以及是否應該在頁首或頁尾載入。

註冊一個新的指令碼。

註冊一個指令碼,以便以後使用wp_enqueue_script()函式進行排隊。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function wp_register_script( $handle, $src, $deps = array(), $ver = false, $in_footer = false ) {
_wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle );
$wp_scripts = wp_scripts();
$registered = $wp_scripts->add( $handle, $src, $deps, $ver );
if ( $in_footer ) {
$wp_scripts->add_data( $handle, 'group', 1 );
}
return $registered;
}
function wp_register_script( $handle, $src, $deps = array(), $ver = false, $in_footer = false ) { _wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle ); $wp_scripts = wp_scripts(); $registered = $wp_scripts->add( $handle, $src, $deps, $ver ); if ( $in_footer ) { $wp_scripts->add_data( $handle, 'group', 1 ); } return $registered; }
function wp_register_script( $handle, $src, $deps = array(), $ver = false, $in_footer = false ) {
	_wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle );

	$wp_scripts = wp_scripts();

	$registered = $wp_scripts->add( $handle, $src, $deps, $ver );
	if ( $in_footer ) {
		$wp_scripts->add_data( $handle, 'group', 1 );
	}

	return $registered;
}

常見問題

FAQs
檢視更多 >