Basic Google Maps Placemarks Shortcodes

Below, you’ll find a detailed guide on how to add the Basic Google Maps Placemarks 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 Basic Google Maps Placemarks Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the Basic Google Maps Placemarks Plugin and the shortcodes it provides:

Plugin Icon
Basic Google Maps Placemarks

"Basic Google Maps Placemarks is a simple, user-friendly WordPress plugin that allows you to easily add and manage custom markers on your Google Maps. Perfect for location-based websites."

★★★★✩ (51) Active Installs: 5000+ Tested with: 4.8.23 PHP Version: false
Included Shortcodes:
  • [bgmp-map]
  • [bgmp-list]

Basic Google Maps Placemarks [bgmp-map] Shortcode

The Basic Google Maps Placemarks (BGMP) shortcode is designed to create a customizable map on your WordPress site. It checks if the necessary JavaScript and CSS files are loaded, returns an error message if not. It also allows for category filtering, and sanitizes the shortcode arguments. The shortcode then initiates the map, and the output is returned.

Shortcode: [bgmp-map]

Examples and Usage

Basic example – A simple map display using the Basic Google Maps Placemarks plugin.

[bgmp-map /]

Advanced examples

Display a map with specific categories of placemarks. The categories are defined in the ‘categories’ parameter. In this example, ‘restaurants’ and ‘hotels’ are the categories of interest.

[bgmp-map categories="restaurants,hotels" /]

Customize the map display by applying filters to the shortcode arguments. Here, the ‘map-shortcode-arguments’ filter is applied to modify the default shortcode attributes.

add_filter( 'bgmp_map-shortcode-arguments', function( $attributes ) {
    $attributes['zoom'] = 15;
    $attributes['center'] = 'London, UK';
    return $attributes;
} );
echo do_shortcode( '[bgmp-map /]' );

Please note that the above PHP code should be added in your theme’s functions.php file or a custom plugin file.

PHP Function Code

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

Shortcode line:

add_shortcode( 'bgmp-map',  array( $this, 'mapShortcode'  ) );

Shortcode PHP function:

function mapShortcode( $attributes ) {
			if ( ! wp_script_is( 'googleMapsAPI', 'queue' ) || ! wp_script_is( 'bgmp', 'queue' ) || ! wp_style_is( self::PREFIX . 'style', 'queue' ) ) {
				$error = sprintf(
					__( '<p class="error">%s error: JavaScript and/or CSS files aren\'t loaded. If you\'re using do_shortcode() you need to add a filter to your theme first. See <a href="%s">the FAQ</a> for details.</p>', 'basic-google-maps-placemarks' ),
					BGMP_NAME,
					'http://wordpress.org/extend/plugins/basic-google-maps-placemarks/faq/'
				);

				// @todo maybe change this to use views/message.php

				return $error;
			}

			if ( isset( $attributes['categories'] ) ) {
				$attributes['categories'] = apply_filters( self::PREFIX . 'mapShortcodeCategories', $attributes['categories'] );
			}   // @todo - deprecated b/c 1.9 output bgmpdata in post; can now just set args in do_shortcode() . also  not consistent w/ shortcode naming scheme and have filter for all arguments now. need a way to notify people

			$attributes = apply_filters( self::PREFIX . 'map-shortcode-arguments', $attributes );   // @todo - deprecated b/c 1.9 output bgmpdata in post...
			$attributes = $this->cleanMapShortcodeArguments( $attributes );

			ob_start();
			do_action( BasicGoogleMapsPlacemarks::PREFIX . 'meta-address-before' );
			require_once( dirname( __FILE__ ) . '/views/shortcode-bgmp-map.php' );
			do_action( BasicGoogleMapsPlacemarks::PREFIX . 'shortcode-bgmp-map-after' );
			$output = ob_get_clean();

			return $output;
		}

Code file location:

basic-google-maps-placemarks/basic-google-maps-placemarks/core.php

Basic Google Maps Placemarks [bgmp-list] Shortcode

The Basic Google Maps Placemarks (BGMP) shortcode is a tool that allows you to list all published placemarks on your site. The shortcode fetches all placemarks, sorts them by title in ascending order, and displays them in a list. If the ‘categories’ attribute is set, it filters placemarks by those categories. The ‘viewonmap’ attribute, when set to true, allows viewing placemarks on the map. If no placemarks are found, it returns a ‘No Placemarks found’ message.

Shortcode: [bgmp-list]

Parameters

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

  • categories – specifies the categories of the placemarks to display
  • viewonmap – if true, shows a link to view the placemark on the map
  • numberposts – determines the number of placemarks to show, -1 means all
  • post_type – specifies the type of post, in this case, placemarks
  • post_status – only shows published placemarks
  • orderby – sorts the placemarks by title
  • order – arranges the placemarks in ascending order

Examples and Usage

Basic example – Display a list of all placemarks in ascending order by title.

[bgmp-list]

Advanced examples

Display a list of placemarks from specific categories. Categories should be specified by their slugs and separated by commas.

[bgmp-list categories="category1,category2"]

Display a list of placemarks and include a ‘View on Map’ link for each placemark.

[bgmp-list viewonmap=true]

Display a list of placemarks from specific categories and include a ‘View on Map’ link for each placemark.

[bgmp-list categories="category1,category2" viewonmap=true]

PHP Function Code

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

Shortcode line:

add_shortcode( 'bgmp-list', array( $this, 'listShortcode' ) );

Shortcode PHP function:

function listShortcode( $attributes ) {
			$attributes = apply_filters( self::PREFIX . 'list-shortcode-arguments', $attributes );
			// @todo shortcode_atts()

			$params = array(
				'numberposts' => -1,
				'post_type'   => self::POST_TYPE,
				'post_status' => 'publish',
				'orderby'     => 'title',
				'order'       => 'ASC'
			);

			if ( isset( $attributes['categories'] ) && ! empty( $attributes['categories'] ) ) {
				// @todo - check each cat to make sure it exists? if not, print error to admin panel.
				// non-existant cats don't break the query or anything, so the only purpose for this would be to give feedback to the admin.

				$params['tax_query'] = array(
					array(
						'taxonomy' => self::TAXONOMY,
						'field'    => 'slug',
						'terms'    => explode( ',', $attributes['categories'] )
					)
				);
			}

			$viewOnMap = isset( $attributes['viewonmap'] ) && $attributes['viewonmap'] == true;

			$posts = get_posts( apply_filters( self::PREFIX . 'list-shortcode-params', $params ) );
			$posts = apply_filters( self::PREFIX . 'list-shortcode-posts', $posts );

			if ( $posts ) {
				$output = '<ul id="' . self::PREFIX . 'list" class="' . self::PREFIX . 'list">';    // Note: id should be removed and everything switched to class, because there could be more than one list on a page. That would be backwards-compatability, though.

				foreach ( $posts as $p ) {
					$address = get_post_meta( $p->ID, self::PREFIX . 'address', true );

					ob_start();
					require( dirname( __FILE__ ) . '/views/shortcode-bgmp-list-marker.php' );
					$markerHTML = ob_get_clean();

					$output .= apply_filters( self::PREFIX . 'list-marker-output', $markerHTML, $p->ID );
				}

				$output .= '</ul>';

				return $output;
			} else {
				return __( 'No Placemarks found', 'basic-google-maps-placemarks' );
			}
		}

Code file location:

basic-google-maps-placemarks/basic-google-maps-placemarks/core.php

Conclusion

Now that you’ve learned how to embed the Basic Google Maps Placemarks 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 *