简便代码快速清理WordPress头部臃肿代码减小页面体积

我们在安装WordPress程序之后是不是看到源代码头部有很多的乱七八糟的代码,这样势必也会增加页面的体积。如果在代码无用可以精简的话,势必会提高页面的速度。这里,麦子整理网上一些通用的代码做法,可以用来减少页面的不必要的头部代码,减少页面体积,提高网站打开速度。

//减少页面头部代码
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', 'start_post_rel_link', 10, 0);
remove_action('wp_head', 'wp_generator');
remove_action('wp_head',  'wp_shortlink_wp_head', 10, 0 );
remove_action('template_redirect', 'wp_shortlink_header', 11 , 0 );
//隐藏JS和CSS版本号
function wpdaxue_remove_cssjs_ver( $src ) {
if( strpos( $src, 'ver=' ) )
$src = remove_query_arg( 'ver', $src );
return $src;
}
add_filter( 'style_loader_src', 'wpdaxue_remove_cssjs_ver', 999 );
add_filter( 'script_loader_src', 'wpdaxue_remove_cssjs_ver', 999 );

这里包括我们取消头部不必要的代码,以及隐藏JS和CSS版本号,减少代码体积。

投票 post
© 版权声明
THE END
喜欢就支持一下吧
点赞11 分享