代码之家  ›  专栏  ›  技术社区  ›  gabriel

需要有关删除操作()的帮助

  •  2
  • gabriel  · 技术社区  · 17 年前

    我正试着移除那些难看的嵌入物 <STYLE> 标记内置的“最近评论”小部件 <HEAD> 但我似乎无法正确理解语法。它最初调用

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

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

    我想应该是这样的:

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

    但是,尽管我尝试过各种各样的变化,我还是不能把它弄好。有人知道如何做到这一点吗?

    可能有帮助:

    4 回复  |  直到 13 年前
        1
  •  8
  •   scribu    17 年前

    这是正确的代码:

    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 .

        2
  •  1
  •   Tyler Carter    17 年前
    remove_action('wp_head', array(&$this, 'recent_comments_style'));
    

    这应该有效,因为WordPress使用相同的函数来创建唯一的ID,不管您是删除还是添加它。

        3
  •  0
  •   OrenM    16 年前
    // 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'  ) );
    }
    

    测试。作品

        4
  •  0
  •   vralle    13 年前

    现在简单地说:

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