Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Code to Disable

Feed URLs on WordPress

29 March, 2023

Thank you for downloading this document.

Haven’t watched the video yet? Click Here

// Remove feed URLs from the header


function disable_feed_links() {
remove_action('wp_head', 'feed_links', 2);
remove_action('wp_head', 'feed_links_extra', 3);
}
add_action('init', 'disable_feed_links');

// Redirect feed requests to the original page


function redirect_feed_requests_to_original_page($query) {
if ($query->is_feed) {
global $wp;
$current_url = home_url(add_query_arg(array(), $wp->request));
$original_url = preg_replace('/\/feed(\/.*|$)/', '', $current_url);
wp_redirect($original_url, 301);
exit;
}
}
add_action('parse_query', 'redirect_feed_requests_to_original_page');

Do not reproduce/repackage/redistribute this sheet without written permission.

Created by https://amittiwari.net/

You might also like