Menu

Flexible Map

Flexible Map

Easily embed Google Maps in WordPress pages and posts

Calling from code

The plugin adds a PHP function flexmap_show_map() for theme and plugin developers. All of the same parameters for the shortcode can be passed to the function in an associative array. If you want it to return the map as a string without output to screen, add "echo"=>"false" to array of attributes.

Sample:

flexmap_show_map(array(
  'center'      => '-34.916721,138.828878',
  'width'       => '100%',
  'height'      => 400,
  'zoom'        => 12,
  'title'       => 'Adelaide Hills',
  'description' => 'The Adelaide Hills are repleat with wineries.',
  'directions'  => 'my-dir-div',
  'hidepanning' => 'false',
  'hidescale'   => 'false',
  'maptype'     => 'satellite',
));

There are also some filter hooks that allow you to change the behaviour of the plugin.

flexmap_google_maps_api_args

filter the array of arguments that will be passed to the Google Maps API, e.g. ‘v’=>’3.exp’, ‘sensor’=>’true’

/**
* change the API version to an earlier one (with caution!)
* @param array $args arguments for the Google Maps API
* @return array
*/
function theme_flexmap_gmaps_args($args) {
    $args['v'] = '3.21';
    return $args;
}
add_filter('flexmap_google_maps_api_args', 'theme_flexmap_gmaps_args');

flexmap_google_maps_api_url

filter the Google Maps API URL, as a string; NB: better to use the flexmap_google_maps_api_args filter if you can.

/**
* replace the current version Google Maps API with "experimental"
* @param string $url the URL to Google Maps API script
* @return string
*/
function theme_flexmap_gmaps_url($url) {
    return 'https://maps.google.com/maps/api/js?v=3.exp';
}
add_filter('flexmap_google_maps_api_url', 'theme_flexmap_gmaps_url');

flexmap_shortcode_attrs

filter the array of shortcode attributes

/**
* disable infowindows, and force directions form
* @param array $attrs shortcode attributes
* @return array
*/
function theme_flexmap_shortcode($attrs) {
    $attrs['showinfo'] = 'false';
    $attrs['showdirections'] = 'true';

    return $attrs;
}
add_filter('flexmap_shortcode_attrs', 'theme_flexmap_shortcode');

flexmap_shortcode_styles

filter the array of inline styles applied to the div wrapping the map, e.g. set the width and height for all maps

/**
* set the width and height parameters on Google maps
* @param array $styles inline styles on the map div
* @param array $attrs shortcode attributes
* @return array
*/
function theme_flexmap_styles($styles, $attrs) {
    $styles['width'] = '100%';
    $styles['height'] = '350px';

    return $styles;
}
add_filter('flexmap_shortcode_styles', 'theme_flexmap_styles', 10, 2);

flexmap_shortcode_script

filter the generated JavaScript

/**
* customise the generated JavaScript
* @param string $script the JavaScript generated for the map
* @param array $attrs shortcode attributes
* @return string
*/
function theme_flexmap_script($html, $script) {
    // your script customisations here...

    return $script;
}
add_filter('flexmap_shortcode_script', 'theme_flexmap_script', 10, 2);

flexmap_shortcode_html

filter the generated html, e.g. wrap another div around it, add a link to Google Maps, add some additional script, etc.

/**
* add some custom HTML after the map
* @param string $html the HTML generated for the map
* @param array $attrs shortcode attributes
* @return string
*/
function theme_flexmap_html($html, $attrs) {
    $html .= "
<p>Your custom HTML here</p>

";

    return $html;
}
add_filter('flexmap_shortcode_html', 'theme_flexmap_html', 10, 2);