请知悉:本文最近一次更新为 7年 前,文中内容可能已经过时。

向取消头部的版本号显示,关闭RSS订阅功能,去掉头部没什么用的连接等部分,就需要优化头部,通常是将代码填写到主题的functions.php文件尾部。
我博客添加的代码如下:

function disable_our_feeds() {
wp_die( __('<strong>Error:</strong> No RSS Feed Available,Please visit our homepage.') );
}
add_action('do_feed','disable_our_feeds',1);
add_action('do_feed_rdf','disable_our_feeds',1);
add_action('do_feed_rss','disable_our_feeds',1);
add_action('do_feed_rss2','disable_our_feeds',1);
add_action('do_feed_atom','disable_our_feeds',1);
function wpbeginner_remove_version() {
return;
}
add_filter( 'script_loader_src', '_remove_script_version', 15, 1 );
add_filter( 'style_loader_src', '_remove_script_version', 10, 2 );
add_filter('the_generator','wpbeginner_remove_version');//wordpress的版本号
remove_action('wp_head','feed_links',2);// 包含文章和评论的feed。
remove_action('wp_head','index_rel_link');//当前文章的索引。
remove_action('wp_head','wlwmanifest_link'); // 外部编辑器
remove_action('wp_head','feed_links_extra',3);// 额外的feed,例如category,tag页
remove_action('wp_head','start_post_rel_link',10,0);// 开始篇
remove_action('wp_head','parent_post_rel_link',10,0);// 父篇
remove_action('wp_head','adjacent_posts_rel_link',10,0); // 上、下篇.
remove_action( 'wp_head','rsd_link');//ML-RPC
remove_action( 'wp_head','adjacent_posts_rel_link_wp_head',10,0 );//rel=”pre”
remove_action( 'wp_head','wp_shortlink_wp_head',10,0 );//rel=”shortlink”
remove_action( 'wp_head','rel_canonical' );
add_filter( 'show_admin_bar', '__return_false' );

网上找的代码整理如下:

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' ); //移除离线编辑器开放接口
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($wp_widget_factory->widgets['WP_Widget_Recent_Comments'] ,'recent_comments_style'));
}

来源:https://www.v7v3.com/wpjiaocheng/201307109.html

按需添加既可。


如您从本文得到了有价值的信息或帮助,请考虑扫描文末二维码捐赠和鼓励。

尊重他人劳动成果。转载请务必附上原文链接,我将感激不尽。


与《WordPress头部优化》相关的博文:


留言

Admin Avatar
😀
😀😁😂😅😭🤭😋😘🤔😰😱🤪💪👍👎🤝🌹👌