函数文档

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.

More Information

  • By default, wp meta() is called immediately after wp_loginout() by sidebar.php and the Meta widget, allowing functions to add new list items to the widget.
  • As the get_sidebar( $name ); function has the do_action( 'get_sidebar', $name ); on top before it loads the sidebar file, this hook should be used to load stuff before the sidebar and wp_meta(); should be called at the end of the sidebar template to allow adding callbacks after the sidebar.

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.

User Contributed Notes