Embed Google Plus Posts in WordPress with Shortcode

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 feature, they say 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.”

The feature is not unlike the same functionality offered by Facebook and Twitter.

The Result

The shortcode of [googleplusembed id="https://plus.google.com/+MartyKhoury/posts/8ZPQm31zT8P"] will return the following:

The post I’ve embedded details an issue I came across in locating the embed code (used outside of the shortcode function). At the time of writing (Nov 2015) Google have rolled out a trial of the “new” Google+, but I’ve failed to find a menu that will display the embed code. That said, with shortcode, you won’t need it… but you will need a correctly formatted post URL. The correct canonical URL format is as follows:

https://plus.google.com/110174288943220639247/posts/cfjDgZ7zK8o

A sample of incorrect formats are custom URLs (https://plus.google.com/+LarryPage/posts/MtVcQaAi684) or a URL with a “u” in them (https://plus.google.com/u/0/106189723444098348646/posts/MtVcQaAi684).

To Obtain a Correct Embed URL

To obtain the correct embed URL, first select the menu option to the top-right of the Google+ post container. Scroll down and click “link to post” (the 4th option in the image). This provides you with the correct canonical URL.

It’s this URL that should be copied into your shortcode function.

Embedding a post from a page URL is no different. This embed comes from the Internoetics Google+ page (using [googleplusembed id="https://plus.google.com/+Internoetics/posts/faaiLPA6rkG"]).

Google’s plusone.js JavaScript

Google’s plusone.js must be included once on your page. While indiscriminately adding JavaScript to every page on your WordPress website is discouraged, we do so because we have follow buttons and other features that rely upon it. If you do not require it on every page, you should use js="1" in your shortcode to include it, or alter the function to read the same so that it displays the JS by default.

If you would like to include Google’s plusone.js on every page, use the following function (in your theme’s functions.php file, or your custom functions file):

The Shortcode Function

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

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

id

The id is the full canonical URL to the public post you would like to embed.

js

As detailed above, if you are required to embed the plusone.js JavaScript, use js="1".

p

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

Download the Code

Download the shortcode function here .

Shortt URL for this post:

Leave a Reply

Your email address will not be published. Required fields are marked *