5

I'm trying to set up WordPress as a CMS. As such, I want to disable the feeds since it's mostly a secured site. I've gone through all the Settings pages but found no setting to tweak or disable the feeds. So I guess I need to write a custom function or plugin to do this. But how?

Concerning what feeds exist, I knew of at least these links...

http://example.com/comments/feed/
http://example.com/feed/

So, in addition to the main question, I'm also slightly worried: does the above code catch all feeds that are available? And is this really the way to disable all feeds?

I know that plugin support is off-topic here. However, just for some context / as a footnote, I'm using the following combination of relevant moving parts:

I've managed to secure access to pages and blog posts using the plugin. However, when unauthenticated users visit a feed URL it still shows content. Because the plugin can't seem to do what I want I decided to write some code myself to do this.

(I've gone through the Appearance > GeneratePress page but nothing is activated. I've also gone through the Appearance > Customize page (and all settings), but found nothing there either. Finally, I've re-read the "Groups" plugin's Options several times over but found no option.)

0

2 Answers 2

5

As pointed out in the comments by @kaiser, your question is very similar to this question. In fact, the question itself holds the answer. To disable all feeds add the following code...

function itsme_disable_feed() {
    wp_die( __( 'No feed available, please visit the <a href="'. esc_url( home_url( '/' ) ) .'">homepage</a>!' ) );
}

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

...to an empty plugin, and activate that plugin. This should prevent anyone from accessing a feed action.

Note that the above is sample code only, preferably you'd not wp_die but redirect or use a 404 instead.

2

Based on the add_feed function, here's a prototype implementation of remove_feed:

/**
 * Remove a feed type like /atom1/.
 *
 * @global WP_Rewrite $wp_rewrite
 *
 * @param string   $feedname Feed name.
 * @return string Feed action name.
 */
function remove_feed( $feedname ) {
        global $wp_rewrite;

        if ( in_array( $feedname, $wp_rewrite->feeds ) ) {
                $wp_rewrite->feeds = array_diff( $wp_rewrite->feeds, array( $feedname ) );
        }

        $hook = 'do_feed_' . $feedname;

        // Remove default function hook
        remove_all_actions( $hook );
        add_action( $hook, $hook );

        return $hook;
}

Usage:

remove_feed( 'rss' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.