Created
November 6, 2022 15:47
-
-
Save AndreFCAmorim/935a35cdc1736b1db61e9f4b032a97d0 to your computer and use it in GitHub Desktop.
Exclude Specific Categories from RSS Feed on WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Exclude a category or multiple categories from the feeds. | |
* If you want to exclude multiple categories, use a comma-separated list: "-15, -5, -6". | |
* Make sure to prefix the category id(s) with a minus "-". | |
* | |
* @param WP_Query $query The query. | |
*/ | |
function wpcode_snippets_exclude_feed_category( $query ) { | |
if ( $query->is_feed ) { | |
// Replace 15 with the desired category id you want to exclude. | |
$query->set( 'cat', '-15' ); | |
} | |
} | |
add_action( 'pre_get_posts', 'wpcode_snippets_exclude_feed_category' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment