3

I want to disable feeds and things like that (rpc, pingbacks, wlwmanifest, prev/next). Reason is that the website is not a blog, so these are of no use.

I wrote the following in a plugin:

remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'feed_links', 2);
remove_action('wp_head', 'wlwmanifest_link');
// and so on...

Indeed the links are no longer in the header. But if I request any of the corresponding url, they still work. I've just removed the links, not the functionality.

I found a hint on wpengineer, and added the following to my plugin:

function fb_disable_feed() {
    wp_die( __('No feed available!') );
}

add_action('do_feed', 'fb_disable_feed', 1);
add_action('do_feed_rdf', 'fb_disable_feed', 1);
add_action('do_feed_rss', 'fb_disable_feed', 1);
add_action('do_feed_rss2', 'fb_disable_feed', 1);
add_action('do_feed_atom', 'fb_disable_feed', 1);

Doesn't seem to work (although I've seen many references to such code).

Any idea on how I could remove all these feeds, rpc and so on? Or at least have them return something like "Nothing here"?

Notes:

  • I don't want to edit core wp files of course!

  • I think the admin area uses feeds. I'm fine with it, I just want them removed from the front end.

  • Have you seen this – Pieter Goosen Feb 28 '16 at 17:56
  • No I had not. I'll dig into it. But I'm still confused that post says adding an action to do_feed* to disable feeds works, as it does not work for me. – Mat Feb 28 '16 at 18:08
  • My bad, disabling rss feeds works with what I wrote above. Don't know what I did before that it didn't work. Now I just have to remove the xmlrpc and wlwmanifest. Will look into that ant post another question if needed. – Mat Feb 28 '16 at 18:20
4

On template_redirect the template-loader.php kicks in.

add_action( 'template_redirect', function() {

    if ( in_array( true,
        array (
            is_feed(),
            is_trackback(),
            is_embed(),
        ) ) ) {
        wp_die( __( "NO SOUP FOR YOU!" ) );
    }
} );

If the do_feed() is called then a few actions can be invoked.

add_action( 'init', function() {

    $feeds = array (
        'do_feed',
        'do_feed_rdf',
        'do_feed_rss',
        'do_feed_rss2',
        'do_feed_atom',
    );

    foreach ( $feeds as $feed ) {
        remove_action( $feed, $feed );
    } 
} );

The above feed actions and many others are added in default-filters.php

To disable xmlrpc:

add_filter( 'xmlrpc_enabled', '__return_false' );

// Hide xmlrpc.php in HTTP response headers
add_filter( 'wp_headers', function( $headers ) {
    unset( $headers[ 'X-Pingback' ] );
    return $headers;
} ); 

To remove links:

remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'rsd_link');

To block access to wlwmanifest and xmlrpc add these lines to your .htaccess:

RedirectMatch 403 ^.*/xmlrpc.php$
RedirectMatch 403 ^.*/wp-includes/wlwmanifest.xml$

For more links to remove you can see Remove JSON API links in header html which includes WP-API & oembed links and Disable emojicons introduced with WP 4.2.

  • Thanks @jgraup. That's an interesting alternative/complement to the above solution that indeed removes rss feeds. I'll think about it and will get back to you. And many thanks for your last edit about xmlrpc. As for the wlwmanifest, that indeed removes the link, but does not disable it. – Mat Feb 28 '16 at 18:25
  • Looks like you may need to add a line to your .htaccess to block access to that file. – jgraup Feb 28 '16 at 19:12
  • I think your answer has all I need and even more. I had already looked at the emojicon thing. Now I have to understand all the details of the code you provided and implement that. Thanks! – Mat Feb 28 '16 at 19:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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