_filter_do_shortcode_context()
云策文档标注
概述
_filter_do_shortcode_context() 是一个 WordPress 过滤器函数,用于在短代码渲染期间修改 wp_get_attachment_image_context 钩子的上下文值。它确保在调用 wp_get_attachment_image() 时,上下文被明确标识为短代码而非主题模板渲染逻辑的一部分。
关键要点
- 该函数在短代码渲染过程中过滤 wp_get_attachment_image_context 钩子。
- 返回字符串 'do_shortcode' 作为 wp_get_attachment_image() 的上下文值。
- 自 WordPress 6.3.0 版本引入。
代码示例
function _filter_do_shortcode_context() {
return 'do_shortcode';
}
原文内容
Filter the wp_get_attachment_image_context hook during shortcode rendering.
Description
When wp_get_attachment_image() is called during shortcode rendering, we need to make clear that the context is a shortcode and not part of the theme’s template rendering logic.
Source
function _filter_do_shortcode_context() {
return 'do_shortcode';
}
Changelog
| Version | Description |
|---|---|
| 6.3.0 | Introduced. |