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.

1 Answer
1

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.

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *