Skip to content

Instantly share code, notes, and snippets.

@pwenzel
Created February 1, 2013 22:45
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pwenzel/4694691 to your computer and use it in GitHub Desktop.
Save pwenzel/4694691 to your computer and use it in GitHub Desktop.
Faux Google Maps oEmbed for Wordpress
<?php
/* Faux Google Maps oEmbed
* Embed google maps in a nicer iframe without using their provided embed code
* @usage Paste a Google Maps link in your post and it will be replaced with an iframe when published
* @link http://bigsaturday.net/oembed-google-maps-wordpress/
*/
wp_embed_register_handler( 'google_map', '#https://maps\.google\.com/maps(.*)#i', 'embed_google_map' );
function embed_google_map( $matches ) {
$query = parse_url($matches[0]);
parse_str($query['query'], $qvars);
$width = isset($qvars['w']) ? $qvars['w'] : 620;
$height = isset($qvars['w']) ? $qvars['h'] : 450;
$embed = '<iframe class="google-map" width="'.$width.'" height="'.$height.'" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="'.$matches[0].'&amp;output=embed"></iframe>';
return apply_filters( 'embed_g_map', $embed );
}
@rickard2
Copy link

To add support for https and other top level domains, use this regular expression:

#https?://maps\.google\.[a-z]+/maps(.*)#i

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment