views:

595

answers:

3

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:

+1  A: 
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.

Chacha102
The problem with this is when add_action was originally called (in `wp-includes/default-widgets.php`), it was in the context of the `WP_Widget_Recent_Comments` class, so `$this` in my theme's `functions.php` file means something else.
gabriel
Then you need to pass it the variable that the instance of the class is in.
Chacha102
I've even tried adding `remove_all_actions("wp_head")` in my `functions.php` and I still see the STYLE tag, so maybe it's getting called earlier? How can I find out?I just want this gone… why are they making this so difficult?
gabriel
If you need a quick solution, you can just not call `wp_head()`. But I'm searching around for more info.
Chacha102
+5  A: 

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.

scribu
Thanks for the info! I figured it'd be something like that, but I couldn't figure out why it wasn't working. I suppose I can live with it until 2.9 gets released.
gabriel
A: 
// 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

OronM