Quantcast
Channel: Disable only the main feed? - WordPress Development Stack Exchange
Viewing all articles
Browse latest Browse all 6

Answer by s_ha_dum for Disable only the main feed?

$
0
0

Very, very quick unscientific research suggests that there is only one query_var set for the main feed. Other feeds such as category, tag, author feeds have more than one query_var. Thus the following should kill the main feed but leave others intact.

add_filter('pre_get_posts',   function($qry) {    if ($qry->is_feed()) {      $fvars = array_filter($qry->query_vars);      if (1 == count($fvars)) {        wp_die( __( 'No feed available, please visit the <a href="'. esc_url( home_url( '/' ) ) .'">homepage</a>!' ) );      }    }  },  1);

To remove the main comment feed, you need a small edit to check for the presence of $fvars['withcomments'].

add_filter('pre_get_posts',   function($qry) {    if ($qry->is_feed() ) {      $fvars = array_filter($qry->query_vars);      if (1 == count($fvars) || isset($fvars['withcomments'])) {        wp_die( __( 'No feed available, please visit the <a href="'. esc_url( home_url( '/' ) ) .'">homepage</a>!' ) );      }    }  },  1);

Be warned: Barely tested. Possibly buggy. Caveat emptor. No refunds.


Viewing all articles
Browse latest Browse all 6

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>