{"id":1002,"date":"2025-03-24T14:28:14","date_gmt":"2025-03-24T14:28:14","guid":{"rendered":"https:\/\/wpgeodirectory.com\/documentation\/article\/how-to-use-iframe-google-maps\/"},"modified":"2025-04-03T15:24:36","modified_gmt":"2025-04-03T14:24:36","slug":"how-to-use-iframe-google-maps","status":"publish","type":"gd_place","link":"https:\/\/wpgeodirectory.com\/documentation\/article\/code-snippets\/how-to-use-iframe-google-maps\/","title":{"rendered":"How to use iFrame Google Maps"},"content":{"rendered":"\n<p>Use the following PHP code snippet to embed Google map to show the listing location.&nbsp;<\/p>\n\n\n\n<p>Step 1:&nbsp;Add the following PHP snippet via snippet plugin or in child theme functions.php file<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-php\">function gd_snippet_embed_google_map_output( $atts, $content = &#039;&#039; ) {\n\tglobal $gd_post;\n\n\tif ( ! empty( $gd_post ) ) {\n\t\tif ( ! empty( $gd_post-&gt;embed_google_map ) ) {\n\t\t\t$embed_url = $gd_post-&gt;embed_google_map;\n\n\t\t\tif ( strpos( $embed_url, &#039;output=embed&#039; ) === false ) {\n\t\t\t\t$embed_url .= &#039;&amp;output=embed&#039;;\n\t\t\t}\n\t\t} else {\n\t\t\t$address = do_shortcode( &#039;&#091;gd_post_meta key=&quot;address&quot; show=&quot;value-strip&quot; no_wrap=&quot;1&quot;&#093;&#039; );\n\t\t\t$address = normalize_whitespace( $address );\n\n\t\t\t$embed_url = &#039;https:\/\/maps.google.com\/maps?q=&#039; . $address . &#039;&amp;t=&amp;z=14&amp;ie=UTF8&amp;iwloc=&amp;output=embed&#039;;\n\t\t}\n\n\t\t$output = &#039;&lt;iframe loading=&quot;lazy&quot; width=&quot;100%&quot; height=&quot;425&quot; frameborder=&quot;0&quot; scrolling=&quot;no&quot; marginheight=&quot;0&quot; marginwidth=&quot;0&quot; src=&quot;&#039; . esc_url( $embed_url ) . &#039;&quot; frameborder=&quot;0&quot; scrolling=&quot;no&quot; marginheight=&quot;0&quot; marginwidth=&quot;0&quot;&gt;&lt;\/iframe&gt;&#039;;\n\t} else {\n\t\t$output = &#039;&#039;;\n\t}\n\n\treturn $output;\n}\nadd_shortcode( &#039;gd_snippet_embed_google_map&#039;, &#039;gd_snippet_embed_google_map_output&#039; );<\/code><\/pre>\n\n\n\n<p><br>Step 2:\u00a0Use shortcode some where on single page template where you want to show map.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&#91;gd_snippet_embed_google_map&#93;<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Use the following PHP code snippet to embed Google map to show the listing location.&nbsp; Step 1:&nbsp;Add the following PHP snippet via snippet plugin or in child theme functions.php file Step 2:\u00a0Use shortcode some where on single page template where you want to show map. &#91;gd_snippet_embed_google_map&#93;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"footnotes":""},"article\/tags":[673,870,871,872],"article\/categories":[211,433],"class_list":["post-1002","gd_place","type-gd_place","status-publish","hentry","gd_place_tags-maps","gd_place_tags-iframe","gd_place_tags-snippet","gd_place_tags-gd-map-snippet","gd_placecategory-tips-tricks-more","gd_placecategory-code-snippets"],"_links":{"self":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/1002","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article"}],"about":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/types\/gd_place"}],"author":[{"embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/comments?post=1002"}],"version-history":[{"count":0,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/1002\/revisions"}],"wp:attachment":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/media?parent=1002"}],"wp:term":[{"taxonomy":"gd_place_tags","embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/tags?post=1002"},{"taxonomy":"gd_placecategory","embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/categories?post=1002"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}