Was ist der beste Weg, Feeds per Post-Typ zu deaktivieren, aber has_archive aktiviert?
Ich bin heute auf dieses Problem gestoßen. Ich weiß nicht, ob es der beste Weg ist, aber hier ist, wie ich es getriggers habe ( has_archive
mit has_archive
):
// First we remove WP default feed actions // If we stop here, feeds would be disabled altogether remove_action('do_feed_rdf', 'do_feed_rdf', 10, 1); remove_action('do_feed_rss', 'do_feed_rss', 10, 1); remove_action('do_feed_rss2', 'do_feed_rss2', 10, 1); remove_action('do_feed_atom', 'do_feed_atom', 10, 1); // Now we add our own actions, which point to our own feed function add_action('do_feed_rdf', 'my_do_feed', 10, 1); add_action('do_feed_rss', 'my_do_feed', 10, 1); add_action('do_feed_rss2', 'my_do_feed', 10, 1); add_action('do_feed_atom', 'my_do_feed', 10, 1); // Finally, we do the post type check, and generate feeds conditionally function my_do_feed() { global $wp_query; $no_feed = array('cpt_1', 'cpt_2'); if(in_array($wp_query->query_vars['post_type'], $no_feed)) { wp_die(__('This is not a valid feed address.', 'textdomain')); } else { do_feed_rss2($wp_query->is_comment_feed); } }
Bitte beachten Sie, dass dies dazu führt, dass alle Feeds als RSS 2.0 generiert werden, wenn sie generiert werden, aber Sie erhalten eine allgemeine Vorstellung.