移除wordpress头部自带的.recentcomments样式

今天在写主题的时候,突然想起wordpress要怎么移除头部里面的

<style type="text/css">.recentcomments a{display:inline !important;padding:0 !important;margin:0 !important;}</style>

于是Google了一下。找到了一个外国网址。 How to remove inline Recent Comments style from WordPress

当然进去之后就找到了答案了。下面与大家一起分享,直说方法,不说为什么wordpress会添加这个莫名的样式上去。

首先,添加下面的样式到你的主题样式style里面。

.recentcomments a{display:inline !important;padding: 0 !important;margin: 0 !important;}

里面说到在2.8以下的可以使用下面代码

function remove_wp_widget_recent_comments_style() {
if ( has _ filter('wp_head' , 'wp_widget_recent_comments_style') ) {
remove _ filter('wp_head' , 'wp_widget_recent_comments_style' );
}
}
add_filter( 'wp_head' , 'remove_wp_widget_recent_comments_style' , 1 );

2.9以上的使用以下代码

function twentyten_remove_recent_comments_style() {
global $ wp _ widget _ factory;
remove _ action( 'wp_head' , array( $ wp _ widget _ factory -> widgets [ 'WP_Widget_Recent_Comments' ] , 'recent_comments_style' ) );
}
add_action( 'widgets_init' , 'twentyten_remove_recent_comments_style' );

添加完毕,收工,不懂的可以在下面自觉提问!

声明: 未经本站许可,谢绝转载!

0 个主题帖 其中:热心观众:0 个, 管理员:0 个

抱歉,评论被关闭