Skip to content

Instantly share code, notes, and snippets.

@sajjadalis
Last active March 1, 2023 09:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sajjadalis/31a7381ead034a07b2f4a0610804d514 to your computer and use it in GitHub Desktop.
Save sajjadalis/31a7381ead034a07b2f4a0610804d514 to your computer and use it in GitHub Desktop.
Create Dynamic Street Map at the end of each post via WP Google Street View plugin and ACF plugin
<?php
// Create 2 advanced custom fields for coordinates (latitude and longitude values).
// Add this code inside theme functions.php file.
// These are the optional parameters which can be included in this shortcode. (width, height, zoom, type)
// Complete shortcode example. [wpgsv_map lat=“VALUE” lng=“VALUE” width=“90%” height=“500px” zoom=“10” type=“street"]
// Demo: https://www.awesomescreenshot.com/video/15190094?key=57963af0866dd6735c54786722d4d6c3
function wpgsv__get_map_after_post_content( $content ) {
if ( function_exists( 'get_field' ) ) {
// Make sure both latitude and longitude field names are the same as you defined in ACF settings.
$lat = get_field('latitude');
$lng = get_field('longitude');
if ($lat && $lng) {
$content .= do_shortcode('[wpgsv_map lat="'.$lat.'" lng="'.$lng.'" height="300px"]');
}
}
return $content;
}
add_filter( 'the_content', 'wpgsv__get_map_after_post_content' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment