wordpress主题wordpress错误_WordPress小技巧:移除菜单导航中自带的多余类名
在我们开发WordPress主题时仔细的小伙伴或发现网站头部若是加载head页面就会泛起许多系统自带的加载项目例如自带的css、js、feed、style等多余信息。
这些加载项目许多是没有必要加载的那么我们如何将这些多余的head头部信息移除呢?
方式很简单网上针对此类WordPress优化的教程也许多今天代码农就给人人整理下。
我们先看看移除多余加载项之前的代码截图
WordPress获取自定义文章类型的所有分类法名称、链接、ID_wordpress教程教程
解决方式
//去除头部多余加载信息
remove_action( \'wp_head\' \'wp_generator\' );//移除WordPress版本
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\' \'feed_links\' 2 );//移除文章和谈论feed
remove_action( \'wp_head\' \'feed_links_extra\' 3 ); //移除分类等feed
remove_action( \'wp_head\' \'rest_output_link_wp_head\' 10 ); //移除wp-json
remove_action( \'wp_head\' \'print_emoji_detection_script\' 7 ); //头部的JS代码
add_filter( \'show_admin_bar\' \'__return_false\' );//移除wp-json链接
remove_action( \'wp_head\' \'rel_canonical\' ); //rel=canonical
remove_action( \'wp_head\' \'wp_shortlink_wp_head\' 10 0 ); //rel=shortlink
//remove_action( \'wp_head\' \'wp_print_styles\' 8 ); //移除后台插件加载css
remove_action( \'wp_head\' \'print_emoji_detection_script\' 7 );//移除emoji载入js
remove_action( \'admin_print_scripts\' \'print_emoji_detection_script\' );//emoji载入js
remove_action( \'wp_print_styles\' \'print_emoji_styles\' );//移除emoji载入css
remove_action( \'admin_print_styles\' \'print_emoji_styles\' );
remove_action( \'wp_head\' \'rest_output_link_wp_head\' 10 );
remove_action(\'wp_head\'\'wp_resource_hints\'2);//移除dns-prefetch
使用方式
将上面代码添加到主题的functions.php文件中 保留后在看看网站的代码。
head头部是不是少了许多多余加载项信息?