DEV Community

Cover image for How to disable WordPress feed with redirect to 404
Alexey
Alexey

Posted on

How to disable WordPress feed with redirect to 404

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

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

function zl_remove_feed_and_redirect() {
    wp_redirect( esc_url( home_url( '404' ) ), 301 );
    die();
}
Enter fullscreen mode Exit fullscreen mode

But I think the redirect should be on through Nginx, before a client-server. Actually, it is a correct solution

Top comments (0)