Send Feed Readers to Your Feed Service
Redirects visitors and feed readers from your main feed to its address at a feed service such as FeedPress or Follow.it, while the service itself still reads your real feed.
Opens WPIDE on
Code
// Your feed's address at the feed service (FeedPress, Follow.it, Feedburner ...). Leave empty to turn the redirect off.
$wpide_feed_service_url = '';
// Parts of the service's user agent; these requests get your real feed so the service can read it.
$wpide_feed_service_agents = array( 'feedpress', 'feedburner', 'follow.it', 'feedvalidator' );
add_action( 'template_redirect', function () use ( $wpide_feed_service_url, $wpide_feed_service_agents ) {
if ( '' === $wpide_feed_service_url || ! is_feed() || is_comment_feed() || is_archive() || is_search() || is_singular() ) {
return;
}
// The service can also read the original feed at /feed/?origin-feed=1.
if ( isset( $_GET['origin-feed'] ) ) {
return;
}
$agent = isset( $_SERVER['HTTP_USER_AGENT'] ) ? strtolower( sanitize_text_field( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) ) ) : '';
foreach ( $wpide_feed_service_agents as $needle ) {
if ( '' !== $agent && false !== strpos( $agent, strtolower( $needle ) ) ) {
return;
}
}
// 302 keeps subscribers on your own feed address, so you can switch services later.
wp_redirect( esc_url_raw( $wpide_feed_service_url ), 302 ); // phpcs:ignore WordPress.Security.SafeRedirect -- external address set by the site owner.
exit;
}, 1 );
Notes
Off until you fill in the service address. Point the service at /feed/?origin-feed=1 if its user agent is not in the list.
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.