Created
February 1, 2013 22:45
-
-
Save pwenzel/4694691 to your computer and use it in GitHub Desktop.
Faux Google Maps oEmbed for Wordpress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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].'&output=embed"></iframe>'; | |
return apply_filters( 'embed_g_map', $embed ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To add support for https and other top level domains, use this regular expression:
#https?://maps\.google\.[a-z]+/maps(.*)#i