
网络开发中的Git:了解一个项目的典型工作流程
wp_get_inline_script_tag ( $javascript, $attributes = array() )
wp_get_inline_script_tag: 这个函数用来为一个内联脚本生成一个脚本标签。它接受一个包含脚本内容的字符串作为唯一的参数,并返回一个HTML脚本标签,该标签可用于在网页中包含该脚本。
在`<script>`标签中包裹内联的JavaScript。
可以通过{@see ‘wp_script_attributes’}过滤器在“标签中注入属性。
如果需要,会自动注入类型属性。
function wp_get_inline_script_tag( $javascript, $attributes = array() ) { 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. * @param string $javascript Inline JavaScript code. */ $attributes = apply_filters( 'wp_inline_script_attributes', $attributes, $javascript ); $javascript = "n" . trim( $javascript, "nr " ) . "n"; return sprintf( "<script%s>%s</script>n", wp_sanitize_script_attributes( $attributes ), $javascript ); }