需要remove_action帮助()(Need help with remove_action()

2019-09-23 02:07发布

我试图去除难看的嵌入式<STYLE>标记在我的内置最新评论插件放<HEAD>但我似乎无法得到正确的语法。 它最初通话

add_action( 'wp_head', array(&$this, 'recent_comments_style') );

添加它(在WP-包括/默认widgets.php,线609 ),和我想撤消。

我想应该是这样的:

remove_action('wp_head', 'WP_Widget_Recent_Comments::recent_comments_style');

但所有我已经试过了变化我仍然不能得到它的权利。 有谁知道如何实现这一目标?

也许有所帮助:

  • 函数参考: remove_action

Answer 1:

这是正确的代码:

add_action('wp_head', 'remove_widget_action', 1);
function remove_widget_action() {
    global $wp_widget_factory;

    remove_action( 'wp_head', array($wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style') );
}

但是,它并没有因为工作的这个bug 。



Answer 2:

remove_action('wp_head', array(&$this, 'recent_comments_style'));

这应该工作,因为WordPress使用相同功能创建的唯一ID是否删除或添加。



Answer 3:

// remove old recentcomments inline style

add_action( 'widgets_init', 'my_remove_recent_comments_style' );
function my_remove_recent_comments_style() {
    global $wp_widget_factory;
    remove_action( 'wp_head', array( $wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style'  ) );
}

测试。 作品



Answer 4:

现在简单的:

// Remove Recent Comments Default Style
add_filter( 'show_recent_comments_widget_style', '__return_false' ); // Temp hack #14876


文章来源: Need help with remove_action()