How to use iFrame Google Maps

Use the following PHP code snippet to embed Google map to show the listing location. 

Step 1: Add the following PHP snippet via snippet plugin or in child theme functions.php file

function gd_snippet_embed_google_map_output( $atts, $content = '' ) {
	global $gd_post;

	if ( ! empty( $gd_post ) ) {
		if ( ! empty( $gd_post->embed_google_map ) ) {
			$embed_url = $gd_post->embed_google_map;

			if ( strpos( $embed_url, 'output=embed' ) === false ) {
				$embed_url .= '&output=embed';
			}
		} else {
			$address = do_shortcode( '[gd_post_meta key="address" show="value-strip" no_wrap="1"]' );
			$address = normalize_whitespace( $address );

			$embed_url = 'https://maps.google.com/maps?q=' . $address . '&t=&z=14&ie=UTF8&iwloc=&output=embed';
		}

		$output = '<iframe loading="lazy" width="100%" height="425" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="' . esc_url( $embed_url ) . '" frameborder="0" scrolling="no" marginheight="0" marginwidth="0"></iframe>';
	} else {
		$output = '';
	}

	return $output;
}
add_shortcode( 'gd_snippet_embed_google_map', 'gd_snippet_embed_google_map_output' );

Step 2: Use shortcode some where on single page template where you want to show map.

[gd_snippet_embed_google_map]
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us