Monthly Archives: July 2015

How to create a basic Google Maps plugin for WordPress

There might be some WordPress plugins out there that could be used to add Google map to posts and pages. Still I didn’t find it necessary to install one when creating it is fun and easy.

Adding the final plugin to a post/page will be done using shortcode.

First of all you must create the plugin directory in wp-content/plugins/plugin_name.

Add two files here, the first an empty index.php and the second plugin_name.php

In order to be able to activate this plugin some basic details need to be added at the beginning:

 * Plugin Name: Custom Google Maps
 * Plugin URI:
 * Description: Create Google Map element using a location query
 * Version: 1.0.0
 * Author: Catalin Munteanu
 * Author URI:

Then we must create a function that will process this plugin’s shortcode:


function google_map_print($attrs, $content=null) {
    $item = shortcode_atts(
            'location' => null

    $result = '<div>';
        $result .= '<iframe
            scrolling="no" marginheight="0" marginwidth="0"
            frameborder="0" style="border:0"
    $result .= '</div>';
    return $result;


add_shortcode('google-map', 'google_map_print');


That’s all. After you activate the plugin you can add it in your posts and pages using the shortcode:

[google-map location="Bucharest"]


[custom-google-map location=”Bucharest”]