wp_meta
云策文档标注
概述
wp_meta 是一个 WordPress 动作钩子,在侧边栏显示回显内容之前触发。它主要用于主题开发,作为事件触发器,允许开发者添加自定义内容到侧边栏。
关键要点
- wp_meta 是一个动作钩子,在侧边栏显示回显内容前触发,用于插入自定义内容。
- 此钩子是主题相关的,可能并非所有主题都包含,但默认的 Meta 小部件在使用时会包含它。
- 作为动作钩子,它主要作为事件触发器,而非内容过滤器,开发者应通过 add_action 添加函数来使用。
代码示例
function your_function() {
echo 'This text is inserted into the sidebar.';
}
add_action('wp_meta', 'your_function');
?>注意事项
使用 wp_meta 时需注意其主题依赖性,确保目标主题支持此钩子,以避免功能失效。
原文内容
Fires before displaying echoed content in the sidebar.
Source
do_action( 'wp_meta' );
Changelog
| Version | Description |
|---|---|
| 1.5.0 | Introduced. |
Skip to note 2 content
Codex
This hook is theme-dependent which means that it is up to the author of each WordPress theme to include it. It may not be available on all themes, so you should take this into account when using it. However, it is included in the default Meta widget when that widget is in use.
This hook is an action which means that it primarily acts as an event trigger, instead of a content filter. This is a semantic difference, but it will help you to remember what this hook does if you use it like this:
function your_function() { echo '<li>This text is inserted into the sidebar.</li>'; } add_action('wp_meta', 'your_function'); ?>