Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How To Syndicate External RSS Feeds In Your WordPress Theme or Child Theme

Some folks don’t realize it, but Wordpress has integrated the ability to syndicate Rss Feeds with some out-of-the-box features. While there are widgets to do this, you may actually want to include the ability to publish other feeds directly into your WordPress template.

WordPress supports both Magpie and SimplePie RSS Caching within its available function, fetch_feed:

  • fetch_feed – retrieve an RSS feed from a URL with automatic caching

This really comes in handy if you have multiple sites and want to share your blog posts on the other sites as soon as they publish. It can also be nice from an SEO standpoint, producing backlinks on another site automatically as you publish your content.

I’ve also utilized this approach to publish podcasts and video feeds from one site to another.

WordPress Theme or Child Theme Template

// Get RSS Feed(s)
include_once( ABSPATH . WPINC . '/feed.php' );
$rss = fetch_feed('https://feed.martech.zone');
if ( ! is_wp_error( $rss ) ) :
$maxitems = $rss->get_item_quantity( 5 ); 
$items = array_slice($rss->get_items, 0, $maxitems);
endif;
?>

    No items'; else foreach ( $items as $item ) : ?>
  • get_permalink() ); ?>' title='get_date('j F Y | g:i a') ); ?>'> get_title() ); ?>

If you publish and don’t immediately see your new post on another site, keep in mind that fetch_feed caches for 12 hours by default. You can modify this by modifying the time interval via the filter wp_feed_cache_transient_lifetime.

function update_cache_time( $seconds )
{
// change the default feed cache recreation period to 1 hour
return (int) 3600;
}

//set feed cache duration
add_filter( 'wp_feed_cache_transient_lifetime', 'update_cache_time');

If you’d like to update the cache for a specific feed, you can apply the filter, fetch the feed, and then reapply the default cache time by updating your code as follows:

// filter to set cache lifetime
add_filter( 'wp_feed_cache_transient_lifetime' , 'update_cache_time' );

$rss = fetch_feed( $feed_url );

// reset the cache lifetime to default value
remove_filter( 'wp_feed_cache_transient_lifetime' , 'update_cache_time' );

Edit your WordPress template (Design > Theme Editor) and place the code where you’d like the feed to publish. There are also a ton of sidebar widgets out there that will publish feeds for you as well.

© %currentyear% DK New Media, LLC, All Rights Reserved.



This post first appeared on How To Optimize Prestashop For Increased SEO And Conversions, please read the originial post: here

Share the post

How To Syndicate External RSS Feeds In Your WordPress Theme or Child Theme

×

Subscribe to How To Optimize Prestashop For Increased Seo And Conversions

Get updates delivered right to your inbox!

Thank you for your subscription

×