print_embed_scripts()
云策文档标注
概述
print_embed_scripts() 函数用于在嵌入 iframe 的头部输出 JavaScript 代码。它通过读取并打印 wp-embed-template.js 文件的内容来实现。
关键要点
- 函数位于 WordPress 核心,用于处理嵌入内容的脚本输出
- 使用 wp_print_inline_script_tag() 来打印内联脚本标签
- 依赖 wp_scripts_get_suffix() 获取脚本后缀以处理压缩版本
- 通过 includes_url() 和 esc_url_raw() 安全生成源 URL
代码示例
function print_embed_scripts() {
$js_path = '/js/wp-embed-template' . wp_scripts_get_suffix() . '.js';
wp_print_inline_script_tag(
trim( file_get_contents( ABSPATH . WPINC . $js_path ) ) . "n//# sourceURL=" . esc_url_raw( includes_url( $js_path ) )
);
}
原文内容
Prints the JavaScript in the embed iframe header.
Source
function print_embed_scripts() {
$js_path = '/js/wp-embed-template' . wp_scripts_get_suffix() . '.js';
wp_print_inline_script_tag(
trim( file_get_contents( ABSPATH . WPINC . $js_path ) ) . "n//# sourceURL=" . esc_url_raw( includes_url( $js_path ) )
);
}
Changelog
| Version | Description |
|---|---|
| 4.4.0 | Introduced. |