最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

theme development - How to remove "prev, next, shortlink" from wp_head()?

programmeradmin2浏览0评论

I'm using these filters to clean the head of my theme:

remove_action('wp_head', 'wp_generator');
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'feed_links', 2);
remove_action('wp_head', 'index_rel_link');
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'feed_links_extra', 3);
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', 'locale_stylesheet');
remove_action('wp_head', 'noindex');
remove_action('wp_head', 'wp_print_styles');
remove_action('wp_head', 'wp_print_head_scripts');

However, I can't seem to get rid of these:

<link rel='prev' title='Top Menu Item 1' href='http://localhost/test/test-prev.html' />
<link rel='next' title='Internal title test default title' href='http://localhost/test/text-next.html' />
<link rel='shortlink' href='http://localhost/test/?p=528' />

I'm using these filters to clean the head of my theme:

remove_action('wp_head', 'wp_generator');
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'feed_links', 2);
remove_action('wp_head', 'index_rel_link');
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'feed_links_extra', 3);
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', 'locale_stylesheet');
remove_action('wp_head', 'noindex');
remove_action('wp_head', 'wp_print_styles');
remove_action('wp_head', 'wp_print_head_scripts');

However, I can't seem to get rid of these:

<link rel='prev' title='Top Menu Item 1' href='http://localhost/test/test-prev.html' />
<link rel='next' title='Internal title test default title' href='http://localhost/test/text-next.html' />
<link rel='shortlink' href='http://localhost/test/?p=528' />
Share Improve this question asked Sep 20, 2011 at 14:53 N2MysticN2Mystic 3,1937 gold badges47 silver badges72 bronze badges 1
  • Outside the scope of your question, but I wouldn't remove wp_print_styles or wp_print_head_scripts. A lot of plugins are going to rely on those to enqueue styles and scripts. Your theme will probably be enqueuing its own styles and scripts as well. – chrisguitarguy Commented Sep 20, 2011 at 16:47
Add a comment  | 

3 Answers 3

Reset to default 1

One shouldn't remove them. They are important for search engines like Google.

One can remove them like this:

remove_action('wp_head', 'wp_shortlink_wp_head');
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');

Here are some additional explanations why they should not be removed and how this effects search engines:

  • Core Code insertion
  • The related trac ticket
  • Google Webmaster Central Article about changes & impact on SEO

In case one removes them, one should really add its own (in case one has changed their links and they are not pointing to the correct urls, that the pagination points to).

Add these to your list:

<?php
remove_action('wp_head', 'wp_shortlink_wp_head');
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');

wp-includes/default-filters.php should be your first stop to check out what WordPress is using its own hook system for.

I've been struggling with this for a while, too, and it appears you should remove action with exactly the same parameters it was added.

so for me the following like in functions.php did the job:

remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10,0);

I'm using WP 3.3.1

发布评论

评论列表(0)

  1. 暂无评论