Pippins Plugins
  • Email
  • Facebook
  • Feedburner
  • Github
  • Google
  • Twitter
  • Vimeo
  • Youtube
  • Rss
  • About
  • News
  • Join the Site
    • Member Benefits
    • Member Plugins
    • Email Notifications
  • Plugin Store
    • Affiliate Area
    • Checkout
  • Plugins
    • Plugin Portfolio
      • Plugin Portfolio – List View
    • Free
    • Premium
    • Member Plugins
    • Coding Standards
    • Get Plugin Support
  • Tutorials
    • Series
      • Plugin Development 101
      • Creating a User Follow System Plugin
      • Customizing Restrict Content Pro
      • Displaying Content with Easy Content Types
      • Writing Your First WordPress Plugins, Basic to Advanced
      • Working with Widgets
      • User Submitted Image Galleries
      • Plugin Thoughts
      • Integrating Stripe.com with WordPress
      • WordPress Rewrite API
    • Member Exclusive
      • Free Members
      • Subscriber Only
    • Difficulty
      • Beginner
      • Intermediate
      • Advanced
    • Action and Filter Hooks
    • Ajax
    • Custom Post Types
    • External APIs
    • Short Codes
    • Taxonomies
    • Video Tutorials
    • Widget Tutorials
    • WordPress Admin / Dashboard
    • Working with jQuery
    • WordPress Database
    • Writing Plugins
    • Tag Index
  • Reviews
  • Support Forum
  • Contact
    • Support the Site
    • Request Code Review
    • Plugin Support

Making a Simple Google +1 Plugin

Posted on July 5, 2011 by Pippin in Beginner, External APIs, Writing Plugins 3 Comments
Home» Tutorials » Beginner » Making a Simple Google +1 Plugin
Tweet
Love It - 1

Google recently releases its Plus One service, and, as usual, dozens of people immediately made WordPress plugins utilizing it. Google Traffic Pop by Tyler Quinn is an excellent example. In this tutorial, I’m going to demonstrate how to make a (very simple) Google +1 plugin for WordPress.

First, you need to create your plugin file (I named mine simple-google-plus-one.php) and place the necessary plugin header code inside it.

1
2
3
4
5
6
7
8
9
<?php
/*
Plugin Name: Simple Google +1 Button
Plugin URI: http://pippinsplugins.commaking-a-simple-google-1-plugin
Description: Adds a Google +1 Button to your posts and pages
Version: 1.0
Author: Pippin Williamson
Author URI: http://184.173.226.218/~pippin
*/

This will make your plugin available to WordPress. Next, we will write a quick function that will load the javascript for the button from Google.

1
2
3
4
function simple_google_plus_one_script() {
	wp_enqueue_script('plusone', 'https://apis.google.com/js/plusone.js');
}
add_action('init', 'simple_google_plus_one_script');

Note the add_action() hook at the bottom. This activates the function (and its contents) when WordPress loads.

And the last part is to write a function that will render the button HTML.

1
2
3
4
5
6
7
function simple_google_plus_one_button($content) {
	if(is_single()) {
		$content .= '<div class="google-plus-one" style="margin: 10px 0;"><g:plusone></g:plusone></div>';
	}
	return $content;
}
add_filter('the_content', 'simple_google_plus_one_button');

I’ve placed the code provided by Google inside of a DIV with a class and an inline style to provide it a little bit of a margin.

Now when you activate the plugin, you will see the Google +1 button rendered at the bottom of your post!

Download the complete plugin below.

Download

Change Log

7-6-11: Adding is_single() conditional so that +1 button only shows up 
on single post pages.

Enjoy!

Tweet Follow @pippinsplugins
google, social

3 comments on “Making a Simple Google +1 Plugin”

  1. Wai Phyo Han says:
    July 11, 2011 at 8:20 am

    Nice post! I’ve write the google +1 plugin for wordpress for last week. In my plugin, I want to use wp_enqueue_script for plusone.js but cannot use. Because I would like to add additional meta data (languages) in script like that

    {lang: ‘fr’}

    So I use wp_head instead. How do I use wp_enqueue_script with additional meata data?

    Here’s my plugins page
    http://wordpress.org/extend/plugins/google-1-social-button/

    Thanks

    Reply
    • pippin says:
      July 11, 2011 at 12:56 pm

      You can probably do it with the wp_localize_script() function. It allows you to pass parameters to your scripts.

  2. Wai Phyo Han says:
    July 13, 2011 at 1:23 pm

    Thanks. I will try it.

    Reply

Leave a Reply Cancel reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

  • Login

Lost your password?

Please enter your username or e-mail address. You will receive a new password via e-mail.

  • Facebook Become a Fan Like

  • Twitter Subscribe on Twitter Follow

  • YouTube Follow my Videos Subscribe

  • RSS Feed Subscribe with RSS Subscribe

Easy Digital Downloads

Most Loved

  • Love It Pro for WordPress
  • Write a “Love It” Plugin with Ajax to Let Users Love Their Favorite Posts / Pages
  • Simple Notices Pro Plugin for WordPress
  • User Bookmarks for WordPress
  • Front End Registration and Login Forms Plugin

Similar Plugins and Posts

Sorry, no related items found.

Latest Premium Content

  • Plugin Development 101 – Introduction to Adding Dashboard Menus
  • Plugin Development 101 – Intro to Loading Scripts and Styles
  • User Follow System – Part 5
  • Plugin Development 101 – Intro to Short Codes

Latest Tutorials

  • Storing Session Data in WordPress without $_SESSION (19)

    The term Session in web development refers to...

  • Test Your Plugins with RTL (1)

    Right-To-Left languages are those that...

  • Submitting Your First Pull Request to a WordPress Plugin on Github (5)

    Github is an extremely popular tool for managing WordPress plugins, and one...

Enter your email to receive automated updates when new posts are published

WP Core Contributions

  • [24316]

View the ticket on Trac.

WP Codex Contributions

  • Function: shortcode exists
  • Function: has shortcode
  • Function: shortcode exists
  • Function: shortcode exists
  • Function: has shortcode

View all 41 changes in the Codex.

Latest Tweets

  • Could not fetch Twitter RSS feed.

Topics

contextual help featured register_setting shortcodes attachments add_options_page Tom McFarlin get_user_meta hook add_shortcode meta box Sugar Event Calendar wp_enqueue_script forms short codes plugin do_action login Related posts authors mail chimp attachment image recent posts post types apply_filters comments short code bbpress taxonomies custom post type Ajax gallery images Stripe taxonomy jquery widgets users add_filter easy content types add_action widget restrict content pro easy digital downloads

Weekly Newsletter

Useful Links

  • Join the Site
  • Plugin Store
  • Affiliate Area
  • Tag Index
  • Support the Site
  • Suggest a Tutorial
  • Random Post
  • Contact

Monthly Archives

(c) 2013 Pippin's Plugins