Last active
March 1, 2023 09:10
-
-
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
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 | |
// 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