wp_meta()
云策文档标注
概述
wp_meta() 是一个主题容器函数,用于触发 'wp_meta' 动作钩子,主要用于在侧边栏显示内容前执行回调函数,支持主题切换等功能。
关键要点
- wp_meta() 函数调用 do_action('wp_meta'),触发 'wp_meta' 动作钩子。
- 默认在 sidebar.php 和 Meta widget 中,wp_meta() 在 wp_loginout() 之后调用,允许向 widget 添加新列表项。
- 建议在侧边栏模板末尾调用 wp_meta(),以便在侧边栏加载后添加回调。
- 与 get_sidebar() 函数配合使用,get_sidebar() 顶部有 do_action('get_sidebar', $name) 钩子,用于侧边栏加载前操作。
代码示例
function wpdocs_my_meta_link() {
echo '<a href="http://www.example.com">' . __( 'My Favourite Link', 'textdomain' ) . '</a>';
}
add_action( 'wp_meta', 'wpdocs_my_meta_link' );
原文内容
Theme container function for the ‘wp_meta’ action.
Description
The ‘wp_meta’ action can have several purposes, depending on how you use it, but one purpose might have been to allow for theme switching.
Source
function wp_meta() {
/**
* Fires before displaying echoed content in the sidebar.
*
* @since 1.5.0
*/
do_action( 'wp_meta' );
}
Hooks
- do_action( ‘wp_meta’ )
-
Fires before displaying echoed content in the sidebar.
Changelog
| Version | Description |
|---|---|
| 1.5.0 | Introduced. |
Skip to note 2 content
Codex
Basic Example
Add a favourite link to the Meta widget:
function wpdocs_my_meta_link() { echo '<li><a href="<a href="http://www.example.com">" rel="nofollow ugc">http://www.example.com"></a>;' . __( 'My Favourite Link', 'textdomain' ) . '</a></li>'; } add_action( 'wp_meta', 'my_meta_link' );