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

Writing a Simple Google Maps Short Code

Posted on September 23, 2012 by Pippin in Advanced, External APIs, Member Restricted, Subscriber Only, Tutorials, Writing Plugins 14 Comments
Home» Tutorials » Advanced » Writing a Simple Google Maps Short Code
Tweet
Love It - 0

In this advanced tutorial we’re going to walk through the process of creating a simple short code to display Google Maps. The concept is simple, but we’ll be using advanced techniques and tools for displaying our maps. All maps will be cached using transients and all requests to Google’s API services will be done with the WordPress HTTP API.

There are a few key techniques utilized to write this plugin:

1. WordPress Short Code API

Most likely you are already familiar with how to register short codes, but just in case you aren’t, the video walks you through how the short code, including several parameters, is setup.

2. Transients API

The WordPress transients API is a really simple caching system that lets you easily store data in the database. It’s great to use when doing remote requests (such as Google Maps) so that you are not forced to perform the request every time the page is loaded.

3. WordPress HTTP API

The WordPress HTTP API provides us with an excellent set of tools for performing remote requests. We can send data remotely, retrieve data remotely, and more. In the scope of this tutorial, we’re using it to send an address to Google and retrieve a set of longitude/latitude coordinates back as a response. This is by far one of my favorite APIs in WordPress.

The maps displayed with the short code we’re writing in this tutorial will look like this screenshot:

The complete code written in the video can be seen below. A further improved version of this plugin will be available in a few days, and it will be free to all premium members.

You must be logged in and have an active premium membership to view the rest of this content. Register or login from the sidebar.


Related Items
  • Plugin Development 101 – Intro to Short Codes
Tweet Follow @pippinsplugins
get_transient, Google Maps, set_transient, wp_remote_get, wp_remote_retrieve_body

14 comments on “Writing a Simple Google Maps Short Code”

  1. FxB says:
    September 24, 2012 at 2:27 am

    Just an amazing tutorial, love the way you explain clearly, i’m really glad to be a member…

    Reply
    • Pippin says:
      September 24, 2012 at 10:21 am

      Great to hear, and great to have you as a member :)

  2. jgalea says:
    September 24, 2012 at 4:06 am

    Excellent tutorial as usual Pippin, an amazing resource for all those who are learning how to write plugins.

    Reply
  3. yellowhousedesign says:
    September 24, 2012 at 11:26 am

    Great tut Pippin! Explanation is always key and was able to follow everything you did; found myself talking to my screen when I saw a syntax mistake ;)

    Not sure if you have it installed, but http://wbond.net/sublime_packages/package_control is a great add-on for Sublime – the WP add-on is pretty awesome-balls as well

    Reply
    • Pippin says:
      September 24, 2012 at 11:43 am

      I didn’t have that installed, but dang, that’s sweet. And yes, the WP add-on is fantastic!

  4. Antoine Divay says:
    January 3, 2013 at 2:46 pm

    Hello Pippin, thanks for the plugin, Is there any php code I can write into my single.php and display a map automatically with my address in the “echo $long_title;”.
    ”,
    ‘width’ => 700 ,
    ‘height’ => 480
    ));
    }

    ?>

    Thanks a lot for your help !

    Reply
    • Pippin says:
      January 3, 2013 at 7:59 pm

      You can use the do_shortcode() function: http://codex.wordpress.org/Function_Reference/do_shortcode

  5. Antoine Divay says:
    January 4, 2013 at 7:35 am

    Does something like work to use your shortcode in my page ?
    ID, ‘emls_property_address’, true);
    echo do_shortcode(‘[pw_map address=$meta]‘);

    ?>

    THanks a lot for your help

    Reply
    • Pippin says:
      January 6, 2013 at 9:43 pm

      Yes it does!

  6. orionrush says:
    January 9, 2013 at 5:43 pm

    You mention that this is going to be a downloadable plugin “in a few days”. Are plans still in the works for this? I assume you wanted to flush it out a bit. By the way, your fly through of the Transients API was very useful for me. Thanks!

    Reply
    • Pippin says:
      January 10, 2013 at 5:02 pm

      It is available: http://wordpress.org/extend/plugins/simple-google-maps-short-code/

  7. orionrush says:
    March 1, 2013 at 3:57 pm

    Pipin, any reason in particular you chose to use XML vs JSON in the wp_remote_get for coordinates? Most of the maps js I’ve worked with uses JSON so I was thinking of trying to convert what you’ve done just to learn.

    Reply
    • Pippin says:
      March 2, 2013 at 4:41 pm

      No, that’s just the format I had available at the time. I personally prefer json.

    • Pippin says:
      March 21, 2013 at 11:40 am

      I just updated the code since Google deprecated v2 of their API. Now it uses json :)

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

  • Simple Google Maps Short Code
  • Sugar Event Calendar – Google Maps

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
  • Plugin Development 101 – Registering a Custom Post Type
  • Plugin Development 101 – Intro to Actions

Latest Tutorials

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

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

  • Plugin Development 101 – Introduction to Adding Dashboard Menus (1)

    Adding new menus, both top level and sub level, to the WordPress Dashboard is a really common task for plugins...

  • Plugin Development 101 – Intro to Loading Scripts and Styles (16)

    In this part of Plugin...

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

Latest Tweets

  • @jaredatch @kimparsell :D
    May 23, 2013
  • @jaredatch there is, as long as there is at least one ticket
    May 23, 2013
  • RT @Astoundify: We are hiring p/t tech support rep for our support forum if your interested email contact [at] http://t.co/bcXNhcwZx5
    May 23, 2013

Topics

wp_enqueue_script Tom McFarlin get_user_meta the_content shortcodes contextual help Sugar Event Calendar featured register_setting meta box attachments add_options_page hook mail chimp Related posts image plugin forms login authors do_action attachment short codes comments recent posts post types apply_filters bbpress short code taxonomies custom post type gallery Ajax images Stripe taxonomy jquery widgets users add_filter add_action easy content types 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) 2011 Pippin's Plugins