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.
 *
 * To override this in a child theme, remove the filter and optionally add your own
 * function tied to the widgets_init action hook.
 *
 * This function uses a filter (show_recent_comments_widget_style) new in WordPress 3.1
 * to remove the default style. Using Twenty Ten 1.2 in WordPress 3.0 will show the styles,
 * but they won't have any effect on the widget in default Twenty Ten styling.
 *
 * @since Twenty Ten 1.0
 */
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。

发表评论

游客欢迎您123

“WordPress 移除头部冗余 recentcomments 样式” 有 3条评论