Skip to content

Instantly share code, notes, and snippets.

@rwkyyy
Created April 22, 2025 10:27
Show Gist options
  • Save rwkyyy/9b3e444afb80a921a147e3b6b04d17aa to your computer and use it in GitHub Desktop.
Save rwkyyy/9b3e444afb80a921a147e3b6b04d17aa to your computer and use it in GitHub Desktop.
disable indexation of feed - in a SEO friendly matter
// Disable RSS Feeds
function disable_rss_feeds() {
status_header( 410 ); // 410 Gone
nocache_headers();
header( 'X-Robots-Tag: noindex, nofollow', true );
header( 'Content-Type: text/html; charset=utf-8' );
echo wp_kses_post(
__( 'Acest feed nu mai este disponibil. Vizitează <a href="' . esc_url( home_url( '/' ) ) . '">pagina principală</a>.' )
);
exit;
}
add_action( 'do_feed', 'disable_rss_feeds', 1 );
add_action( 'do_feed_rdf', 'disable_rss_feeds', 1 );
add_action( 'do_feed_rss', 'disable_rss_feeds', 1 );
add_action( 'do_feed_rss2', 'disable_rss_feeds', 1 );
add_action( 'do_feed_atom', 'disable_rss_feeds', 1 );
add_action( 'do_feed_rss2_comments', 'disable_rss_feeds', 1 );
add_action( 'do_feed_atom_comments', 'disable_rss_feeds', 1 );
// Remove RSS feed links from header
remove_action( 'wp_head', 'feed_links', 2 );
remove_action( 'wp_head', 'feed_links_extra', 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment