禁用RSS源,禁用自我Pingbacks

禁用RSS源

RSS源主要也是用来订阅网站文章的,但是现在基本没人用,反而给采集文章的人带来了便利。所以说不想使用的可以直接禁止掉。

function itsme_disable_feed() {
  wp_die( __( 'No feed available, please visit the <a href="'. esc_url( home_url( '/' ) ) .'">homepage</a>!' ) );
}

add_action('do_feed', 'itsme_disable_feed', 1);
add_action('do_feed_rdf', 'itsme_disable_feed', 1);
add_action('do_feed_rss', 'itsme_disable_feed', 1);
add_action('do_feed_rss2', 'itsme_disable_feed', 1);
add_action('do_feed_atom', 'itsme_disable_feed', 1);
add_action('do_feed_rss2_comments', 'itsme_disable_feed', 1);
add_action('do_feed_atom_comments', 'itsme_disable_feed', 1);

写入functions.php即可

禁用后我们的每个页面还是有RSS地址的,所以我们把这个地址也删除

remove_action( 'wp_head', 'feed_links_extra', 3 );
remove_action( 'wp_head', 'feed_links', 2 );

写入functions.php即可.

禁用自我Pingbacks

当你自己文章里调用了自己的某个文章链接时候wordpress会创建一个自我Pingbacks,这个东西没有什么价值。可以禁用。

function no_self_ping( &$links ) {
$home = get_option( 'home' );
foreach ( $links as $l => $link )
  if ( 0 === strpos( $link, $home ) )
    unset($links[$l]);
}
add_action( 'pre_ping', 'no_self_ping' );

写入functions.php保存即可