_wp_footer_scripts()
云策文档标注
概述
_wp_footer_scripts() 是一个私有函数,专用于 *_footer_scripts hooks。在经典主题中,当块样式通过 wp_load_classic_theme_block_styles_on_demand() 按需加载时,此函数会被 wp_hoist_late_printed_styles() 中的闭包替换,以捕获并提升“延迟”样式到 HEAD 部分。
关键要点
- _wp_footer_scripts() 是私有函数,不应直接调用,仅用于 *_footer_scripts hooks。
- 在经典主题中,当块样式按需加载时,此函数被替换为闭包,用于提升延迟样式到 HEAD:块相关样式插入在 wp-block-library 样式表后,其他样式追加到 HEAD 末尾。
- 函数内部调用 print_late_styles() 和 print_footer_scripts() 来打印延迟样式和页脚脚本。
- 自 WordPress 3.3.0 版本引入。
代码示例
function _wp_footer_scripts() {
print_late_styles();
print_footer_scripts();
}注意事项
- 此函数为私有,开发者应避免直接使用,而是通过相关 hooks 如 wp_footer_scripts 来操作。
- 在块主题或现代主题中,此函数的行为可能不同,需根据主题类型调整样式加载策略。
原文内容
Private, for use in *_footer_scripts hooks
Description
In classic themes, when block styles are loaded on demand via wp_load_classic_theme_block_styles_on_demand() , this function is replaced by a closure in wp_hoist_late_printed_styles() which will capture the printing of two sets of “late” styles to be hoisted to the HEAD by means of the template enhancement output buffer:
- Styles related to blocks are inserted right after the wp-block-library stylesheet.
- All other styles are appended to the end of the HEAD.
The closure calls print_footer_scripts() to print scripts in the footer as usual.
Source
function _wp_footer_scripts() {
print_late_styles();
print_footer_scripts();
}
Changelog
| Version | Description |
|---|---|
| 3.3.0 | Introduced. |