Skip to content

Instantly share code, notes, and snippets.

@faisalahammad
Created January 8, 2025 03:40
Show Gist options
  • Save faisalahammad/9852331e77c8e1e2059d274e24a5a7bd to your computer and use it in GitHub Desktop.
Save faisalahammad/9852331e77c8e1e2059d274e24a5a7bd to your computer and use it in GitHub Desktop.
This code snippet disables all feed types in WordPress (RSS, Atom, RDF) and displays a custom message directing users to the homepage. Ideal for sites that do not want to offer feed capabilities.
function wpb_disable_feed() {
wp_die( __('No feed available, please visit our <a href="' .
get_bloginfo('url') . '">homepage</a>!') );
}
add_action('do_feed', 'wpb_disable_feed', 1);
add_action('do_feed_rdf', 'wpb_disable_feed', 1);
add_action('do_feed_rss', 'wpb_disable_feed', 1);
add_action('do_feed_rss2', 'wpb_disable_feed', 1);
add_action('do_feed_atom', 'wpb_disable_feed', 1);
add_action('do_feed_rss2_comments', 'wpb_disable_feed', 1);
add_action('do_feed_atom_comments', 'wpb_disable_feed', 1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment