Need help with remove_action()

僤鯓⒐⒋嵵緔 提交于 2019-12-07 18:48:27

问题


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:

  • Function Reference: remove_action

回答1:


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.




回答2:


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.




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

tested. works




回答4:


Now simply:

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


来源:https://stackoverflow.com/questions/1261764/need-help-with-remove-action

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!