RBA Cash Rate: 4.35% · 1AUD = 0.67 USD · Inflation: 4.1%  
Leading Digital Marketing Experts | 1300 235 433 | Aggregation Enquires Welcome | Book Appointment
Example Interest Rates: Home Loan Variable: 5.38% (6.14%*) • Home Loan Fixed: 5.44% (6.26%*) • Fixed: 5.44% (6.26%*) • Variable: 5.38% (6.14%*) • Investment IO: 5.69% (6.52%*) • Investment PI: 5.49% (5.98%*)

Add a Google +1 Button in WordPress with Shortcode

Add a Google +1 Button in WordPress with Shortcode

The Google +1 button now forces a share dialogue rather than behaving like the Facebook 'like' button. The bizarre move essentially depreciates the former feature that was, quite frankly, one of the more redeeming features of the platform.

Note: Google+ is now a retired platform for personal use. The demos have been disabled.

The button offered "social proof" by providing visible credibility to a page. While the +1 was never a entirely accurate indication of article or page popularity (it was flawed because of the somewhat misleading count), fixing the intrinsic feature was always a better option of removing it. The site is called Google Plus and they've disabled the flagship feature - the Google Plus button. Could you image if Facebook removed the 'like' button and instead forced a share?

The +1 button was also a good quasi-bookmarking service since all +1 impressions were available from within Google+... and it was an easy means of sharing something without having to actually share it. To introduce a new experience (we can't call it a feature) without notice is ridiculously negligent on Google's part. Did they learn nothing from Twitter? To suggest that they've "[made] it easier for people to load and share the pages they're interested in" is absurd. Forcing the share dialogue box is nothing more than a means to inject life into a product that isn't working. Fix the platform, Google - don't kill its features.

■ ■ ■

We'll reluctantly share the WordPress shortcode to render a +1 button (or should we call it a share button?) on your website with shortcode.

The Result

The result can be seen at the top of this page by way of a +a button alongside the Tweet button. There are four button size: small, medium, standard, and tall. If you're using our former shortcode function and have defined depreciated attributes, they obviously have no effect.

small

Shortcode: [gpone size="small"]. Result:

Demo removed.

medium

The shortcode of [gpone size="medium"] will return as follows:

Demo removed.

standard

The standard +1 button, written as [gpone size="standard"] will display as follows:

Demo removed.

tall

The tall +1 button [gpone size="tall"], previously associated with a count icon (now more of a 'flat' button), will render as follows:

Demo removed.

Button width, maximum width, and button height are detailed on Google's developer website . A reproduction of the new sizing is reproduced below.

Add a Google +1 Button in WordPress with Shortcode

Source: https://developers.google.com/+/web/+1button/#button-sizes.

The doubling up of buttons is the result of attributes that were depreciated.

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
 Add a Google +1 Button in WordPress with Shortcode
4
 http://www.beliefmedia.com/google-plus-one-wordpress
5
*/
6
 
7
function beliefmedia_google_plusone_button($atts) {
8
 
9
  $atts = shortcode_atts(array(
10
    'url' => 0, /* data-href */
11
    'size' => 'medium', /* data-size: small, medium, standard, tall */
12
    'width' => '60', /* data-width */
13
    'align' => 'left',
14
    'callback' => 0, /* data-callback */
15
    'interaction' => 0, /* data-onstartinteraction */
16
    'endinteraction' => 0, /* data-onendinteraction */
17
    'style' => 'padding-left: 3px; display:inline-block; float: right;', /* Additional style for container div */
18
    'p' => 0
19
  ), $atts);
20
 
21
  /* Uses post permalink by default */
22
  $url = ($atts['url']) ? $atts['url'] : get_permalink();
23
  if ($atts['style'] == '') $style = 'float: ' . $atts['align'] . ';';
24
 
25
  /* Build button */
26
  $return = '<div style="' . $atts['style'] . ' width: ' . $width . ';">';
27
  $return .= '<div class="g-plusone" data-annotation="inline" data-size="' . $atts['size'] . '" data-width="' . $atts['width'] . '" data-href="' . $url . '"';
28
  if ($atts['callback']) $return .= ' data-callback="' . $atts['callback'] . '"';
29
  if ($atts['interaction']) $return .= ' data-onstartinteraction="' . $atts['interaction'] . '"';
30
  if ($atts['endinteraction']) $return .= ' data-onendinteraction="' . $atts['endinteraction'] . '"';
31
  $return .= '></div>
32
</div>';
33
  if ($atts['p']) $return = '' . $return . '';
34
 
35
 return $return;
36
}
37
add_shortcode('gpone','beliefmedia_google_plusone_button');

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

url

Under normal circumstances the URL should be left blank so it defaults to the WordPress post permalink. To alter this and add another a +1 for another page,
use url="http://www.flight.org/".

size

Available button sizes are small, medium, standard, and tall.

width

Width of the parent div container.

align

Sets the float property of the align attribute.

style

The style is applied to Google's div container. If empty the container will align as defined by the align attribute.

■ ■ ■

callback

If specified, this function is called after the user clicks the +1 button.

interaction

If specified, this function is called either when a hover bubble displays, which is caused by the user hovering the mouse over the +1 button, or when a confirmation bubble displays, which is caused by the user +1'ing the page.

endinteraction

If specified, this function is called when either a hover or confirmation bubble disappears.

PHP Function

As with the shrotcode function, you must include Google's platform.js code. Download the code here.

1
<?php 
2
/*
3
 Add a Google +1 Button in WordPress with Shortcode
4
 http://www.beliefmedia.com/google-plus-one-wordpress
5
*/
6
 
7
function beliefmedia_plusone($url = 'false', $args = '') {
8
 
9
  /* Require URL */
10
  if ($url === false) return 'Require URL';
11
 
12
  $atts = array(
13
    'size' => 'medium', /* data-size: small, medium, standard, tall */
14
    'width' => '60', /* data-width */
15
    'align' => 'left',
16
    'callback' => 0, /* data-callback */
17
    'interaction' => 0, /* data-onstartinteraction */
18
    'endinteraction' => 0, /* data-onendinteraction */
19
    'style' => 'padding-left: 3px; display:inline-block; float: right;', /* Additional style for container div */
20
    'p' => 0
21
  );
22
 
23
  /* Merge $args with $atts */
24
  $atts = (empty($args)) ? $atts : array_merge($atts, $args);
25
 
26
  /* You'll need to add your own style... */
27
  if ($atts['style'] == '') $style = 'float: ' . $atts['align'] . ';';
28
 
29
  /* Build button */
30
  $return = '<div style="' . $atts['style'] . ' width: ' . $width . ';">';
31
  $return .= '<div class="g-plusone" data-annotation="inline" data-size="' . $atts['size'] . '" data-width="' . $atts['width'] . '" data-href="' . $url . '"';
32
  if ($atts['callback']) $return .= ' data-callback="' . $atts['callback'] . '"';
33
  if ($atts['interaction']) $return .= ' data-onstartinteraction="' . $atts['interaction'] . '"';
34
  if ($atts['endinteraction']) $return .= ' data-onendinteraction="' . $atts['endinteraction'] . '"';
35
  $return .= '></div>
36
</div>';
37
  if ($atts['p']) $return = '' . $return . '';
38
 
39
 return $return;
40
}
41
 
42
/* Usage */
43
$url = 'http://www.beliefmedia.com/';
44
$args = array('size' => 'standard');
45
echo beliefmedia_plusone($url);

Considerations

  • More information on the Google +1 button can be found here .
  • Our styles are rather generic so it's very likely you will have to alter the CSS style to ensure your button renders as you would like.
  • In our former article we shared details on how to include the button at the top and bottom of each page. When that code is published you'll find it here.

Download

Downloads Removed.

■ ■ ■

 
Download our complimentary 650-page guide on marketing for mortgage brokers. We'll show you exactly how we generate billions in volume for our clients.
Finance Guide, Cropped Top and Bottom
  Timezone: 1 · [ CHANGE ]

RELATED READING

Like this article?

Share on Facebook
Share on Twitter
Share on Linkdin
Share on Pinterest

Leave a comment