DEV Community

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

Posted on

3 1

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)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay