WordPress代码移除wp自带head的css等无用杂项
在我们使用Wordpress的时候,都会使用自己喜欢好主题模板,但是wordpress已经写好了自己默认的css js等杂项代码,然而我们并不需要,那么我们怎么删除这些没有的代码呢?今天归一就给大家整理了一下发布出来方法也是非常简单
代码:
//去除头部多余加载信息
remove_action( 'wp_head', 'wp_generator' );
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 );
remove_action( 'wp_head', 'feed_links_extra', 3 );
remove_action( 'wp_head', 'rest_output_link_wp_head', 10 );
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
add_filter( 'show_admin_bar', '__return_false' );
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 );
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
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);
使用方式:
将以上代码复制到主题目录,路径: 找到自己使用的模板主题 – functions.php最末位置粘贴即可,最后带上简化截图
