Advertisement
Guest User

Untitled

a guest
May 27th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. <?php
  2. add_action( 'wp_head', 'remove_feeds_from_wp_head', 1 );
  3. /**
  4. * Remove feed links from wp_head
  5. */
  6. function remove_feeds_from_wp_head() {
  7.  
  8. // Remove feed links
  9. remove_action( 'wp_head', 'feed_links', 2 );
  10. remove_action( 'wp_head', 'feed_links_extra', 3 );
  11.  
  12. // Remove Really Simple Discovery Link
  13. remove_action( 'wp_head', 'rsd_link' );
  14.  
  15. // Remove referecne to index page
  16. remove_action('wp_head', 'index_rel_link');
  17. }
  18.  
  19. foreach( array( 'rdf', 'rss', 'rss2', 'atom' ) as $feed ) {
  20. add_action( 'do_feed_' . $feed, 'remove_feeds', 1 );
  21. }
  22. unset( $feed );
  23. /**
  24. * prefect actions from firing on feeds when the `do_feed` function is
  25. * called
  26. */
  27. function remove_feeds() {
  28. // redirect the feeds! don't just kill them
  29. wp_redirect( home_url(), 302 );
  30. exit();
  31. }
  32.  
  33. add_action( 'init', 'kill_feed_endpoint', 99 );
  34. /**
  35. * Remove the `feed` endpoint
  36. */
  37. function kill_feed_endpoint() {
  38. // This is extremely brittle.
  39. // $wp_rewrite->feeds is public right now, but later versions of WP
  40. // might change that
  41. global $wp_rewrite;
  42. $wp_rewrite->feeds = array();
  43. }
  44.  
  45. register_activation_hook( __FILE__, 'activation_hook' );
  46. /**
  47. * Activation hook
  48. */
  49. function activation_hook() {
  50. kill_feed_endpoint();
  51. flush_rewrite_rules();
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement