- Unknown
- January 21, 2016
- PHP, WordPress, WordPress plugin
- {No} comments
AOA, Hello our reader today I decided to make a tutorial on making a simple WordPress plugin that can get images of map from google maps static api, and display in the post using shortcut, this is very useful plugin. Its say if you want to display map images of where you eat last time, then you just need to put address in short code and the plugin will show map image
First of all we need to make our plugin basic structure, WordPress reads comment in PHP file to define plugin name and url, author name, etc.
Now this is full code of this plugin
First of all we need to make our plugin basic structure, WordPress reads comment in PHP file to define plugin name and url, author name, etc.
/*
Plugin Name: Create Map Image
Plugin URI: http://meralesson.com/
Description: Whenever you want to show any map in post then this plugin is for you
Author: Aizaz.dinho
Version: 1.0
Author URI: http://meralesson.com/
*/
Example:
<?php
/*
Plugin Name: Create Map Image
Plugin URI: http://meralesson.com/
Description: Whenever you want to show any map in post then this plugin is for you
Author: Aizaz.dinho
Version: 1.0
Author URI: http://meralesson.com/
*/
function create_map_image($data,$content=null){
//Google map api
$api_url = 'https://maps.google.com/maps/api/staticmap?sensor=false&size=600x300&format=png¢er=';
//we add array in shortcode using wordpress function
shortcode_atts( array( 'title' => 'Your Map:', 'address' => ''), $data);
//Show the data from returned array
return '
' . $data['title'] . '
';
}
//final make shortcode: now when user type [create_map] then map image will return
add_shortcode('create_map','create_map_image');
?>
Usage: when user use this shortcode then the map image will return in post
[create_map title="GIVE TITLE" address="YOUR MAP ADDRESS HERE"]
so when you add the above shortcode in your post html then you'll get your map image
0 comments:
Post a Comment