WordPress是个很优秀的博客程序,当然,现在发展到多功能阶段,什么站都能做。

但就是因为WordPress的功能太多了,太臃肿了,想必很多用过免费空间的都感觉WordPress好像很迟钝的样子,是的事实就是这样,因为WordPress现在太过臃肿,每载入一个页面都要进行很多无谓操作。

今天就说说WordPress头部的事。

WordPress总是自作主张地载入普通人不需要的东西,本来就没什么用,还降低博客的载入速度,当然要去除,但是你翻查主题代码你会发现头部貌似没有载入什么无用的信息,那是因为那些无用信息都是通过一个叫wp_head()的钩子随着网页载入而自动输出的。很简单,去掉相关钩​​子。

算了,博主不是行家,直接给出代码,代码来自v7v3,把代码扔到主题的functions.php就好了。

remove_action( 'wp_head', 'wp_enqueue_scripts', 1 ); //Javascript的调用
remove_action( 'wp_head', 'feed_links', 2 ); //移除feed
remove_action( 'wp_head', 'feed_links_extra', 3 ); //移除feed
remove_action( 'wp_head', 'rsd_link' ); //移除离线编辑器开放接口 < /li>
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 );//载入css
remove_action( 'wp_head', 'wp_print_head_scripts', 9 );
remove_action( 'wp_head', 'wp_generator' ); //移除WordPress版本
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($w​​p_widget_factory->widgets['WP_Widget_Recent_Comments'] ,'recent_comments_style'));
}

以上大部分代码的作用都用注释标注出来了​​,需要保留那些,你们可以根据自己的要求来注释掉,好了,至此wordpress头部的瘦身减肥就完成了,网站速度是不是快了很多呢?