Australia's Leading Digital Marketing Experts. T. 1300 235 433  |  Aggregation Enquires Welcome

Example Interest Rates: Home Loan Variable: 2.54% (2.74%*) • Home Loan Fixed: 3.74% (3.8%*) • Fixed: 2.48% (2.94%*) • Variable: 2.54% (2.74%*) • Investment IO: 2.3% (3.76%*) • Investment PI: 2.04% (3.8%*)

Embed Google Plus Posts in WordPress

Embed Google Plus Posts in WordPress

Note: Google+ is now a depreciated platform. The article is for reference only.

Continuing in the spirit of articles that detail some Google+ features for WordPress, the latest post will show you how to embed a Google Plus post into a WordPress post or page with shortcode.

From Google's 2013 blog post detailing the new (at the time) feature, they said that "... with embedded posts, site owners can now add your public Google+ posts to their web pages - as a primary source, for example, or to highlight your point of view. Text, photo and media posts are all supported, and the embeds are fully interactive, so visitors can +1, comment and follow you inline."

Since the post by Google was first written, Google have removed the +1 feature and they've buried the share options so deep into the system that they're impossible to find (if indeed they even still exist). Despite our somewhat wavering commitment to Google Plus, this post will show you how to embed a Google+ post into your WordPress website with shortcode.

To avoid constructing an invalid URL, we've altered the function since it was first published on Internoetics.

The Result

The shortcode of [googleplusembed user="+MartyKhoury" post="8ZPQm31zT8P"] will return the following:

No longer available

The correct canonical URL format for an embed (as constructed in our shortcode) is as follows:

https://plus.google.com/nnnnnnnnnnnnnnnnn/posts/XXXXXXXXXXXXX

Embedding a post from a page URL is no different to that of a user. An old post from the Internoetics Google+ page (using [googleplusembed id="+Internoetics" post="faaiLPA6rkG"] is as follows:

No longer available

WordPress Shortcode

This function requires that Google's Platform JavaScript function be rendered on your page. You can download the function or plugin here.

Copy and paste the WordPress function into your theme's functions.php file or, if you sensibly have one installed, your custom functions plugin.

1
<?php 
2
/*
3
 Embed Google Plus Posts in WordPress
4
 http://www.beliefmedia.com/google-plus-posts-wordpress
5
*/
6
 
7
function beliefmedia_googleplus_embed_post($atts) {
8
  $atts = shortcode_atts(array(
9
    'user' => '+MartyKhoury',
10
    'post' => '8ZPQm31zT8P',
11
    'p' => 1
12
  ), $atts);
13
 
14
  $return .= '<div style="margin: 0 auto; width: 440px; max-width: 95%;">
15
<div class="g-post" data-href="https://plus.google.com/' . $atts['user'] . '/posts/' . $atts['post'] . '"></div>
16
</div>';
17
 
18
  /* Wrap in paragraph tags for WP */
19
  if ($atts['p']) $return = '' . $return . '';
20
 
21
 return $return;
22
}
23
add_shortcode('googleplusembed', 'beliefmedia_googleplus_embed_post');

If you require shortcode to work in a sidebar widget, you'll have to enable the functionality with a filter. If you're using our custom functions plugin, you'll have that feature enabled by default.

Shortcode Attributes

user

The id or username of the Google+ user or page.

post

The post ID. The ID is the string of text after /posts/ in the URL.

p

The embedded post will be wrapped in paragraph tags by default. If you don't require this, use p="0".

PHP Function

Used outside of WordPress, the following may be used. Use of Google's platform.js JavaScript is required.

1
<?php 
2
/*
3
 Embed Google Plus Posts in WordPress
4
 http://www.beliefmedia.com/google-plus-posts-wordpress
5
*/
6
 
7
function beliefmedia_googleplus_embed_post($user = '+MartyKhoury', $post = '8ZPQm31zT8P', $p = true) {
8
 
9
  $return .= '<div style="margin: 0 auto; width: 440px; max-width: 95%;">
10
<div class="g-post" data-href="https://plus.google.com/' . $user . '/posts/' . $post . '"></div>
11
</div>';
12
 
13
  /* Wrap in paragraph tags for WP */
14
  if ($p !== false) $return = '' . $return . '';
15
 
16
 return $return;
17
}

Usage is as follows:

1
/* Usage */
2
echo beliefmedia_googleplus_embed_post($user = '+MartyKhoury', $post = '8ZPQm31zT8P');

Download

No longer available.

Download our 650-page guide on Finance Marketing. We'll show you exactly how we generate Billions in volume for our clients.

  AUS Eastern Standard Time (Washington)

  Want to have a chat?
 

RELATED READING

Like this article?

Share on facebook
Share on Facebook
Share on twitter
Share on Twitter
Share on linkedin
Share on Linkdin
Share on pinterest
Share on Pinterest

Leave a comment