第一步:从站点的部分删除提要链接。
<?php
add_action( \'wp_head\', \'wpse33072_wp_head\', 1 );
/**
* Remove feed links from wp_head
*/
function wpse33072_wp_head()
{
remove_action( \'wp_head\', \'feed_links\', 2 );
remove_action( \'wp_head\', \'feed_links_extra\', 3 );
}
接下来,让我们从WP中删除提要端点。钩入
init
, 全球化
$wp_rewrite
然后将提要设置为空数组。这有效地阻止了WordPress添加提要重写。它也是超级黑客,将来可能会在某个时候崩溃。
<?php
add_action( \'init\', \'wpse33072_kill_feed_endpoint\', 99 );
/**
* Remove the `feed` endpoint
*/
function wpse33072_kill_feed_endpoint()
{
// This is extremely brittle.
// $wp_rewrite->feeds is public right now, but later versions of WP
// might change that
global $wp_rewrite;
$wp_rewrite->feeds = array();
}
但是,如果它坏了,没关系,因为我们会将提要重定向到主页。
<?php
foreach( array( \'rdf\', \'rss\', \'rss2\', \'atom\' ) as $feed )
{
add_action( \'do_feed_\' . $feed, \'wpse33072_remove_feeds\', 1 );
}
unset( $feed );
/**
* prefect actions from firing on feeds when the `do_feed` function is
* called
*/
function wpse33072_remove_feeds()
{
// redirect the feeds! don\'t just kill them
wp_redirect( home_url(), 302 );
exit();
}
最后一步:激活挂钩,将重写提要设置为空数组,并刷新重写规则。
<?php
register_activation_hook( __FILE__, \'wpse33072_activation\' );
/**
* Activation hook
*/
function wpse33072_activation()
{
wpse33072_kill_feed_endpoint();
flush_rewrite_rules();
}
所有这些
as a plugin.