widget_meta_poweredby
云策文档标注
概述
widget_meta_poweredby 是一个 WordPress 内置 Meta 小工具中的过滤器,用于修改小工具底部“WordPress.org”链接的 HTML 输出。开发者可以通过此过滤器自定义链接内容或替换为其他链接。
关键要点
- 过滤器名称:widget_meta_poweredby,属于 Meta 小工具的一部分。
- 参数:$html(默认 HTML 字符串)和 $instance(当前小工具设置数组)。
- 功能:允许修改或替换默认的“WordPress.org”链接,常用于添加自定义 powered by 链接。
- 注意事项:过滤器函数必须返回一个值,否则输出可能为空。
代码示例
add_filter( 'widget_meta_poweredby', 'custom_meta_poweredby' );
function custom_meta_poweredby( $html, $instance ) {
// 替换为自定义 powered by 链接
return '<a href="http://ma.tt" title="More Awesome by Matt Mullenweg">More Awesome by Matt Mullenweg</a>';
}注意事项
从 WordPress 4.9.0 版本开始,添加了 $instance 参数;此过滤器在 3.6.0 版本中引入。确保过滤器函数正确处理参数并返回有效 HTML 字符串。
原文内容
Filters the “WordPress.org” list item HTML in the Meta widget.
Parameters
$htmlstring-
Default HTML for the WordPress.org list item.
$instancearray-
Array of settings for the current widget.
Source
echo apply_filters(
'widget_meta_poweredby',
sprintf(
'<li><a href="%1$s">%2$s</a></li>',
esc_url( __( 'https://wordpress.org/' ) ),
__( 'WordPress.org' )
),
$instance
);
Skip to note 2 content
Steven Lin
Example Migrated from Codex:
Replacing with a custom powered by link.
add_filter( 'widget_meta_poweredby', 'custom_meta_poweredby' ); function custom_meta_poweredby( $html, $instance ) { // Replace with custom powered by link return ' More Awesome by <a href="<a href="http://ma.tt"" rel="nofollow ugc">http://ma.tt"</a>; title="More Awesome by Matt Mullenweg">Matt Mullenweg</a>'; }