WordPress删除不必要的meta标签

2.4k 记录 一条评论

WordPress默认情况下引用系统 wp_head() 获得很多的 meta 标签,其中有一些不太必要,所以我们可以通过 add_filter 和 remove_action 删除这些标签。

打开主题下的 functions.php 文件,加入下面的内容:

add_filter('the_generator', 'wpbeginner_remove_version');
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'wp_generator');
remove_action('wp_head', 'start_post_rel_link');
remove_action('wp_head', 'index_rel_link');
remove_action('wp_head', 'parent_post_rel_link');
remove_action('wp_head', 'adjacent_posts_rel_link');
remove_action('wp_head', 'rel_canonical');
remove_action('wp_head', 'feed_links', 2 );
remove_action('wp_head', 'feed_links_extra', 3 );
remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0 );

再删除主题下的 header.php 如下的内容:

<link rel="profile" href="http://gmpg.org/xfn/11" />
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" />
这样,这些不需要的 meta 标签就会从博客前台消失了。

1条评论

says: 回复

谢谢分享,很受用,

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

昵称 *