A-A+
清除 wordpress 插件生成的头部代码
我们在使用一些 wordpress 插件的时候,经常会在页面的顶部,也就是网页的 head 之间产生一些插件代码,当不使用这些插件的时候,会产生冗余代码,从而导致一些插件不能正常的使用问题,怎样才能将这些代码进行批量删除掉呢,下面看一段因插件产生的代码清理方法,代码如下:
<?php //remove_action( "wp_head", "wp_enqueue_scripts", 1 ); remove_action( "wp_head", "feed_links", 2 ); remove_action( "wp_head", "feed_links_extra", 3 ); remove_action( "wp_head", "rsd_link" ); remove_action( "wp_head", "wlwmanifest_link" ); remove_action( "wp_head", "index_rel_link" ); remove_action( "wp_head", "parent_post_rel_link", 10, 0 ); remove_action( "wp_head", "start_post_rel_link", 10, 0 ); remove_action( "wp_head", "adjacent_posts_rel_link_wp_head", 10, 0 ); //remove_action( "wp_head", "locale_stylesheet" ); remove_action( "publish_future_post", "check_and_publish_future_post", 10, 1 ); //remove_action( "wp_head", "noindex", 1 ); //remove_action( "wp_head", "wp_print_styles", 8 ); //remove_action( "wp_head", "wp_print_head_scripts", 9 ); remove_action( "wp_head", "wp_generator" ); //remove_action( "wp_head", "rel_canonical" ); remove_action( "wp_footer", "wp_print_footer_scripts" ); remove_action( "wp_head", "wp_shortlink_wp_head", 10, 0 ); remove_action( "template_redirect", "wp_shortlink_header", 11, 0 ); 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")); } ?>
将本代码放入到主题 funtions.php 文件中就可以了。
本方法主要利用了remove_action函数,关于本函数就不多介绍了,如果有兴趣的话可以到wp官网上面看一下。
试试这个