Need help with remove_action()

2019-05-21 13:50发布

I'm trying to remove the unsightly embedded <STYLE> tag the built-in Recent Comments widget puts in my <HEAD>, but I can't seem to get the syntax right. It originally calls

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

to add it (in wp-includes/default-widgets.php, line 609), and I'm trying to undo it.

I think it should be something like this:

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

but with all the variations I've tried I still can't get it right. Does anyone know how to achieve this?

Possibly Helpful:

4条回答
再贱就再见
2楼-- · 2019-05-21 14:23

This is the correct code:

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

However, it doesn't work because of this bug.

查看更多
啃猪蹄的小仙女
3楼-- · 2019-05-21 14:23
// 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'  ) );
}

tested. works

查看更多
We Are One
4楼-- · 2019-05-21 14:25
remove_action('wp_head', array(&$this, 'recent_comments_style'));

This should work because Wordpress uses the same functions to create the unique IDs whether you remove or add it.

查看更多
ゆ 、 Hurt°
5楼-- · 2019-05-21 14:38

Now simply:

// Remove Recent Comments Default Style
add_filter( 'show_recent_comments_widget_style', '__return_false' ); // Temp hack #14876
查看更多
登录 后发表回答