wp_get_script_tag

函式
wp_get_script_tag ( $attributes )
引數
  • (array) $attributes Key-value pairs representing `<script>` tag attributes.
    Required:
返回值
  • (string) String containing `<script>` opening and closing tags.
定義位置
相關方法
wp_get_inline_script_tagwp_print_script_tagwp_get_post_tagswp_set_post_tagswp_get_script_polyfill
引入
5.7.0
棄用
-

wp_get_script_tag: 這是一個WordPress的函式,用來生成HTML標籤,以便在WordPress站點中排隊等待指令碼。它接受一個指令碼屬性和選項的陣列,例如指令碼的源URL、依賴性、版本號,以及指令碼是否應該被載入到頁面的頁首或頁尾。它返回一個包含指令碼標籤的HTML標記的字串。

格式化`<script>`載入器標籤。

可以通過{@see ‘wp_script_attributes’}過濾器在“標籤中注入屬性。如果需要,會自動注入型別屬性。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function wp_get_script_tag( $attributes ) {
if ( ! isset( $attributes['type'] ) && ! is_admin() && ! current_theme_supports( 'html5', 'script' ) ) {
$attributes['type'] = 'text/javascript';
}
/**
* Filters attributes to be added to a script tag.
*
* @since 5.7.0
*
* @param array $attributes Key-value pairs representing `<script>` tag attributes.
* Only the attribute name is added to the `<script>` tag for
* entries with a boolean value, and that are true.
*/
$attributes = apply_filters( 'wp_script_attributes', $attributes );
return sprintf( "<script%s></script>n", wp_sanitize_script_attributes( $attributes ) );
}
function wp_get_script_tag( $attributes ) { if ( ! isset( $attributes['type'] ) && ! is_admin() && ! current_theme_supports( 'html5', 'script' ) ) { $attributes['type'] = 'text/javascript'; } /** * Filters attributes to be added to a script tag. * * @since 5.7.0 * * @param array $attributes Key-value pairs representing `<script>` tag attributes. * Only the attribute name is added to the `<script>` tag for * entries with a boolean value, and that are true. */ $attributes = apply_filters( 'wp_script_attributes', $attributes ); return sprintf( "<script%s></script>n", wp_sanitize_script_attributes( $attributes ) ); }
function wp_get_script_tag( $attributes ) {
	if ( ! isset( $attributes['type'] ) && ! is_admin() && ! current_theme_supports( 'html5', 'script' ) ) {
		$attributes['type'] = 'text/javascript';
	}
	/**
	 * Filters attributes to be added to a script tag.
	 *
	 * @since 5.7.0
	 *
	 * @param array $attributes Key-value pairs representing `<script>` tag attributes.
	 *                          Only the attribute name is added to the `<script>` tag for
	 *                          entries with a boolean value, and that are true.
	 */
	$attributes = apply_filters( 'wp_script_attributes', $attributes );

	return sprintf( "<script%s></script>n", wp_sanitize_script_attributes( $attributes ) );
}

常見問題

FAQs
檢視更多 >