WordPress 移除头部冗余 recentcomments 样式

Wordpress在很多头部会有多余的recentcomments 样式,这是由最新评论小工具引起的,无论有没有使用这个小工具,都会添加的多余的代码。
虽然不影响我们对主题的样式进行修改,但是莫名其妙多出来一段代码也是比较不爽。WordPress 官方似乎也意识到了这个问题,在 WordPress 3.1 之后添加了一个过滤函数show_recent_comments_widget_style,我们可以利用这个函数移除头部多余的代码,将以下函数添加到 WordPress 主题根目录下functions.php 文件中即可:

/**
 * Remove the default styles that are packaged with the Recent Comments widget.
 */
function twentyten_remove_recent_comments_style() {
    add_filter( 'show_recent_comments_widget_style', '__return_false' );
}
add_action( 'widgets_init', 'twentyten_remove_recent_comments_style' );

以上这段代码来自WordPress 官方主题TwentyTen。

发表评论


  1. Warning: copy(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/wwwroot/hanost/wp-content/themes/lerm/functions.php on line 613

    Warning: copy(https://cn.gravatar.com/avatar/2b621d52e8f13ef796e9081b4839e97e?s=50&d=mm&r=g): failed to open stream: php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/wwwroot/hanost/wp-content/themes/lerm/functions.php on line 613
    webkv
    回复

    这个方法很不错,收藏了。


    1. Warning: copy(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/wwwroot/hanost/wp-content/themes/lerm/functions.php on line 613

      Warning: copy(https://cn.gravatar.com/avatar/ccc8e0e30838fa69434ac9c5d8f99f9e?s=50&d=mm&r=g): failed to open stream: php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/wwwroot/hanost/wp-content/themes/lerm/functions.php on line 613
      智慧宫
      回复

      请多多指教