2

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:

gabriel
  • 1,787
  • 2
  • 19
  • 24
  • The second argument for `add_action` / `remove_action` uses `call_user_func_array` syntax, so maybe that knowledge will help. – gabriel Aug 11 '09 at 17:37

4 Answers4

8

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
  • 2,958
  • 4
  • 34
  • 44
  • 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 Aug 13 '09 at 13:10
1
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.

Tyler Carter
  • 60,743
  • 20
  • 130
  • 150
  • 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 Aug 11 '09 at 17:30
  • Then you need to pass it the variable that the instance of the class is in. – Tyler Carter Aug 11 '09 at 17:31
  • 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 Aug 12 '09 at 17:55
  • If you need a quick solution, you can just not call `wp_head()`. But I'm searching around for more info. – Tyler Carter Aug 12 '09 at 18:14
0

Now simply:

// Remove Recent Comments Default Style
add_filter( 'show_recent_comments_widget_style', '__return_false' ); // Temp hack #14876
vralle
  • 514
  • 6
  • 6
0
// 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

OrenM
  • 369
  • 3
  • 13