Keep Certain Authors' Posts Out of Feeds
Leaves posts by the authors you list, such as guest writers or an automated account, out of your main feeds, while their author feed and the posts on the site stay available.
Opens WPIDE on
Code
// User IDs or usernames whose posts stay out of the main feeds. Empty = off. Example: array( 7, 'guest-writer' ).
$wpide_feed_hidden_authors = array();
add_action( 'pre_get_posts', function ( $query ) use ( $wpide_feed_hidden_authors ) {
if ( ! $wpide_feed_hidden_authors || is_admin() || ! $query->is_main_query() || ! $query->is_feed() || $query->is_author() || $query->is_comment_feed() ) {
return;
}
$ids = array();
foreach ( $wpide_feed_hidden_authors as $author ) {
$user = is_numeric( $author ) ? get_user_by( 'id', (int) $author ) : get_user_by( 'login', $author );
if ( $user ) {
$ids[] = (int) $user->ID;
}
}
if ( $ids ) {
$query->set( 'author__not_in', array_unique( array_merge( (array) $query->get( 'author__not_in' ), $ids ) ) );
}
} );
Notes
The author list is empty by default; add user IDs or usernames.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.