钩子文档

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.

More Information

  • The “widget_meta_poweredby” filter is part of the build in Meta widget. This filter allows you to alter the powered by link at the bottom of the widget. By default, this links to WordPress.org.
  • Note that the filter function must return an value after it is finished processing or the result will be empty.

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
);

Changelog

Version Description
4.9.0 Added the $instance parameter.
3.6.0 Introduced.

User Contributed Notes

  1. Skip to note 2 content

    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&quot" rel="nofollow ugc">http://ma.tt"</a>; title="More Awesome by Matt Mullenweg">Matt Mullenweg</a>';
    }