WP Elite

Wordpress, web design and SEO tips

How to display your Google Plus feeds to your WordPress blog?

Google+(Google Plus) is currently latest project of Google. Other say that Google+ will be the ultimate rival of Facebook, but as of now Google+ is still in beta state. If you’re a Google+ user and you have a WordPress blog, you may want to display your feeds from Google+ to your WordPress blog. As of now Google+ API is not yet released, compared to Facebook’s API which has a very wide range apps you can connect in to your WordPress blog. Today i will teach you how display your Google+ feeds to your WordPress blog just like Twitter and Facebook feeds.

function wp_gplus_feeds( $id, $count = 5 ){
	include_once(ABSPATH . WPINC . '/feed.php');
	$rss = fetch_feed("http://plusfeed.appspot.com/$id");
	if ( !is_wp_error( $rss ) ) :
		$maxitems = $rss->get_item_quantity( $count );
		$feed_items = $rss->get_items( 0, $maxitems );
	endif;
	echo '<ul>';
		if ( $maxitems == 0 ):
			echo '<li class="gplus_feed_items">No Feeds</li>';
		else:
			foreach ( $feed_items as $item ) :
				echo '<li class="gplus_feed_items">';
					$link = '<a href="'. esc_url( $item->get_permalink() ) .'" title="Posted: '. $item->get_date("j F Y | g:i a"). '">';
					$link .= esc_html( $item->get_title() ) . '</a>';
					echo $link;
				echo '</li>';
			endforeach;
		endif;
	echo '</ul>';
}

We created a function to wrap things up. We need to include feed.php so that we can take advantage of the SimplePie API included in our WordPress core files. We need to use the unofficial Google+ user feeds application called PlusFeed to pull our feeds from Google+. Using the fetch_feed function with our PlusFeed URL, we are now fetching all our Google+ user feeds.

After we fetch all our feed from Google+, all we need to do is loop all our feed items, just like looping to WP_Query post.

We need to get our Google+ ID, the underlined numbers on the picture above shows your Google+ ID.

<?php wp_gplus_feeds( '1111111111111111' ); ?>

Pasting this code with your Google+ ID using wp_gplus_feeds function in your WordPress sidebar or in any part of your theme will display 5 latest post from your Google+ user account.

<?php wp_gplus_feeds( '1111111111111111', 3 ); ?>

We can also set the number of feeds to display, by adding a second argument on our function we can control the maximum number of feeds to return.

That’s it guys we can now include our Google+ user feeds on our WordPress blog. This is very useful if want to target our Google+ user or share contents using the new Google+.

Filed Under: Blog

Copyright © 2023 · WPLeet.com