如何从wp_head()中删除“Prev,Next,Shorlink”?

时间:2011-09-20 作者:N2Mystic

我正在使用这些过滤器来清理主题的头部:

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\');
然而,我似乎无法摆脱这些:

<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\' />

3 个回复
最合适的回答,由SO网友:kaiser 整理而成

不应该移除它们。它们对像谷歌这样的搜索引擎很重要。

可以这样删除它们:

remove_action(\'wp_head\', \'wp_shortlink_wp_head\');
remove_action(\'wp_head\', \'adjacent_posts_rel_link_wp_head\');
这里有一些额外的解释,解释为什么不应该删除它们,以及这对搜索引擎的影响:

如果删除了它们,应该真正添加自己的链接(如果更改了链接,并且它们没有指向分页所指向的正确URL)。

SO网友:chrisguitarguy

将以下内容添加到您的列表中:

<?php
remove_action(\'wp_head\', \'wp_shortlink_wp_head\');
remove_action(\'wp_head\', \'adjacent_posts_rel_link_wp_head\');
wp-includes/default-filters.php 应该是你第一站,看看WordPress使用自己的钩子系统做什么。

SO网友:Donald

我也为此挣扎了一段时间,似乎您应该删除与添加的参数完全相同的操作。

因此,对于我来说,函数中有以下类似项。php完成了这项工作:

remove_action(\'wp_head\', \'adjacent_posts_rel_link_wp_head\', 10,0);
我正在使用WP 3.3.1

结束

相关推荐