在remove_action()方面需要帮助

时间:2009-08-11 17:12:57

标签: php wordpress wordpress-plugin wordpress-theming

我正在尝试删除内置的“最近评论”窗口小部件放入<STYLE>中的难看的嵌入式<HEAD>标记,但我似乎无法正确使用语法。它最初调用

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

添加它(在wp-includes/default-widgets.php, line 609中),我正在尝试撤消它。

我认为它应该是这样的:

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

但是我尝试了所有的变化,但仍然无法做到。有谁知道如何实现这个目标?

可能有帮助:

4 个答案:

答案 0 :(得分:8)

这是正确的代码:

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

但是,由于this bug,它无效。

答案 1 :(得分:1)

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

这应该有效,因为无论您删除还是添加它,Wordpress都会使用相同的功能创建唯一ID。

答案 2 :(得分: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'  ) );
}

测试。作品

答案 3 :(得分:0)

现在简单地说:

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