WordPress Snippets at WPcustoms

301 Redirect your feed to feedburner

Your default feed url with permalinks is by default yoursite.com/feed/. This function replaces this with your feedburner url and a 301 permanent redirect. No manual code changing in your header is required. Just place this snippet in your functions.php file and don’t forget to update the feedburner feed url.


/**
 * Snippet Name: 301 Redirect your feed to feedburner
 * Snippet URL: https://wpcustoms.net/snippets/301-redirect-your-feed-to-feedburner/
 */
  
function wpc_rssfeed_redirect() {
	if ( is_feed() AND !preg_match( '/feedburner|feedvalidator/i', $_SERVER['HTTP_USER_AGENT'] ) ){
		header( 'Location: http://feeds.feedburner.com/your_custom_feed' );
		header( 'HTTP/1.1 301 Permanent Redirect' );
	}
}
add_action( 'template_redirect' , 'wpc_rssfeed_redirect');