Interactive Geo Maps Shortcodes

Below, you’ll find a detailed guide on how to add the Interactive Geo Maps Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Interactive Geo Maps Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the Interactive Geo Maps Plugin and the shortcodes it provides:

Plugin Icon
Interactive Geo Maps

"Interactive Geo Maps is a versatile WordPress plugin that helps you create and showcase vibrant, customizable maps on your website. It's perfect for geographical data visualization."

★★★★☆ (47) Active Installs: 30000+ Tested with: 6.4 PHP Version: 7.0
Included Shortcodes:
  • [display-map]
  • [map-title-current]
  • [map-dropdown]
  • [map-list]

Interactive Geo Maps [display-map] Shortcode

The Interactive Geo Maps plugin shortcode, ‘display-map’, dynamically generates and displays a map based on user attributes. It validates the map ID, ensures it’s of the correct post type ‘igmap’, then renders the map. It also adds footer scripts.

Shortcode: [display-map]

Parameters

Here is a list of all possible display-map shortcode parameters and attributes:

  • id – Unique identifier for the specific map to display
  • meta – Additional metadata for more complex map configurations
  • regions – Specifies the geographical regions to be included in the map
  • roundmarkers – Determines whether markers on the map are round or not
  • demo – If set, displays a demo version of the map for testing purposes

Examples and Usage

Basic example – A simple map display using the shortcode by referencing the ID of the map.

[display-map id=1 /]

Advanced examples:

Displaying a map with specific regions highlighted. The regions are identified by their codes, separated by commas.

[display-map id=1 regions="US,CA,MX" /]

Displaying a map with round markers. The markers are identified by their codes, separated by commas.

[display-map id=1 roundmarkers="US,CA,MX" /]

Displaying a map with a demo attribute. This can be used for testing or showcasing purposes.

[display-map id=1 demo=true /]

Displaying a map with meta attribute. This can be used to add additional information to the map.

[display-map id=1 meta="Population: 300 million" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [display-map] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'display-map', array( $this, 'render_shortcode' ) );

Shortcode PHP function:

function render_shortcode( $atts, $content = null, $tag = '' )
    {
        // normalize attribute keys, lowercase
        $atts = array_change_key_case( (array) $atts, CASE_LOWER );
        // override default attributes with user attributes
        $map_atts = shortcode_atts( array(
            'id'           => null,
            'meta'         => null,
            'regions'      => null,
            'roundmarkers' => null,
            'demo'         => null,
        ), $atts, $tag );
        if ( !isset( $map_atts['id'] ) ) {
            return;
        }
        $map_atts['id'] = (int) $map_atts['id'];
        if ( $map_atts['id'] === 0 ) {
            return;
        }
        $id_post_type = get_post_type( $map_atts['id'] );
        if ( $id_post_type !== 'igmap' ) {
            return;
        }
        $map = new Plugin\Map( $this );
        $html = $map->render( $map_atts, $this );
        // add footer scripts
        add_action( 'wp_footer', array( $this, 'footer_content' ) );
        return $html;
    }

Code file location:

interactive-geo-maps/interactive-geo-maps/src/Core.php

Interactive Geo Maps [map-title-current] Shortcode

The Interactive-Geo-Maps plugin shortcode ‘map-title-current’ dynamically displays the title of the current map. If a title is present, it renders as “[Title] Map Preview”; if not, it defaults to “World Map Preview”.

Shortcode: [map-title-current]

Examples and Usage

Basic example – The shortcode is used to render the title of the current interactive map. If there is no specified title, it will default to ‘World Map Preview’.

[map-title-current /]

PHP Function Code

In case you have difficulties debugging what causing issues with [map-title-current] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'map-title-current', array( $this, 'render_map_current_title' ) );

Shortcode PHP function:

function render_map_current_title( $atts ) {

		$title = $this->get_current();

		if ( $title !== '' ) {
			/* translators: %s is the name of the current map displaying */
			$html = sprintf( __( '%s Map Preview', 'interactive-geo-maps' ), $title );
		} else {
			$html = __( 'World Map Preview', 'interactive-geo-maps' );
		}

		return sprintf( '<h2>%s</h2>', $html );

	}

Code file location:

interactive-geo-maps/interactive-geo-maps/src/Plugin/Utils/MapListCurrent.php

Interactive Geo Maps [map-dropdown] Shortcode

Interactive Geo Maps plugin shortcode, ‘map-dropdown’, dynamically generates a dropdown list of maps. This shortcode retrieves the list of maps using the ‘MapList’ class, decodes the JSON data, and builds an HTML select element.

Shortcode: [map-dropdown]

Examples and Usage

Basic example – Map dropdown shortcode is used to render a dropdown list of all available maps.

[map-dropdown /]

PHP Function Code

In case you have difficulties debugging what causing issues with [map-dropdown] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'map-dropdown', array( $this, 'render_map_dropdown' ) );

Shortcode PHP function:

function render_map_dropdown( $atts ) {

		$map_list = new MapList();
		$options  = json_decode( $map_list->maps, true );

		$html = $this->build_select( $options );

		return $html;

	}

Code file location:

interactive-geo-maps/interactive-geo-maps/src/Plugin/Utils/MapListDropdown.php

Interactive Geo Maps [map-list] Shortcode

The Interactive Geo Maps shortcode, ‘map-list’, is designed to render a list of maps. This shortcode fetches a list of all available maps using the MapList class. It then decodes the JSON data into an array. If a ‘group’ attribute is set in the shortcode, it filters the options array to only include the specified group of maps. The shortcode finally builds an HTML list of the maps using the build_list function.

Shortcode: [map-list]

Parameters

Here is a list of all possible map-list shortcode parameters and attributes:

  • group – Specifies the group of maps to display in the list.

Examples and Usage

Basic example – A simple usage of the map-list shortcode to render a map list.

[map-list /]

For more complex and tailored usage, you can use attributes to specify the map group you want to display. This is particularly useful when you have different groups of maps and want to display a specific one.

Advanced examples

Displaying a specific map group using the ‘group’ attribute. This example will only render the maps that belong to the group named ‘Europe’.

[map-list group='Europe' /]

Another advanced usage can be to display multiple map groups. In this example, the shortcode will render the maps belonging to the groups ‘Europe’ and ‘Asia’.

[map-list group='Europe, Asia' /]

Please note that the group names are case-sensitive and should match exactly as you have defined in your MapList settings. If a group name does not exist, the shortcode will not render any maps for that group.

PHP Function Code

In case you have difficulties debugging what causing issues with [map-list] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'map-list', array( $this, 'render_map_list' ) );

Shortcode PHP function:

function render_map_list( $atts ) {

		$map_list = new MapList();
		$options  = json_decode( $map_list->maps, true );

		if( isset( $atts['group'] ) && isset( $options[ $atts['group'] ] ) ){
			$options = [ $atts['group'] => $options[ $atts['group'] ] ];
		}

		$html = $this->build_list( $options );

		return $html;

	}

Code file location:

interactive-geo-maps/interactive-geo-maps/src/Plugin/Utils/MapListOutput.php

Conclusion

Now that you’ve learned how to embed the Interactive Geo Maps Plugin shortcodes, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

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