
如何使用WordPress钩子来提高技术性SEO
wp_get_script_tag ( $attributes )
wp_get_script_tag: 这是一个WordPress的函数,用来生成HTML标签,以便在WordPress站点中排队等待脚本。它接受一个脚本属性和选项的数组,例如脚本的源URL、依赖性、版本号,以及脚本是否应该被加载到页面的页眉或页脚。它返回一个包含脚本标签的HTML标记的字符串。
格式化`<script>`加载器标签。
可以通过{@see ‘wp_script_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 ) ); }