Skip to content

Instantly share code, notes, and snippets.

@SCRWD
Created May 14, 2010 21:30
Show Gist options
  • Select an option

  • Save SCRWD/401700 to your computer and use it in GitHub Desktop.

Select an option

Save SCRWD/401700 to your computer and use it in GitHub Desktop.
// jon.posterous.com
// adds google maps search links to postcodes
add_filter( "the_content", "googlemaps_link");
function googlemaps_link( $x )
{
// Regexp based on http://regexlib.com/REDetails.aspx?regexp_id=2268
return preg_replace('@(>[^<]*?)(GIR ?0AA|(?:[A-PR-UWYZ](?:\d|\d{2}|[A-HK-Y]\d|[A-HK-Y]\d\d|\d[A-HJKSTUW]|[A-HK-Y]\d[ABEHMNPRV-Y]))) ?(\d[ABD-HJLNP-UW-Z]{2})([^<]*?<)@i', '\\1<a href="http://maps.google.co.uk/maps?q=\\2+\\3" target="_blank">\\2 \\3</a>\\4', $x);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment