In this tutorial, you’ll see how to center the map on a specific marker when loading the map page.
- For this to work, you’ll have to add the attribute
post_id
to the URL. For example, if you want to navigate from your website’s homepagewww.website.com
to your map pagewww.website.com/map
, you’ll have to add the attributepost_id
to that URL with the real post ID as its value. In our example, your URL should bewww.website.com/map/?post_id=15
where15
is the real post ID. - Edit the file “functions.php” of your theme/child theme and copy/paste the following code in it:
function cspm_center_map_on_specific_post($default, $map_id){ if(isset($_GET['post_id'])){ $post_id = esc_attr($_GET['post_id']); $latitude = get_post_meta($post_id, CSPM_LATITUDE_FIELD, true); $longitude = get_post_meta($post_id, CSPM_LONGITUDE_FIELD, true); $output = " setTimeout(function(){ cspm_center_map_at_point(plugin_map, map_id, '".$latitude."', '".$longitude."', 'zoom'); }, 500);"; echo $output; } } add_filter('cspm_after_map_load', 'cspm_center_map_on_specific_post', 10, 2);
In the same context
- Open the single post page inside a modal
- Programmatically change single map language based on the URL’s language attribute
- Synchronize the ACF map field with the map fields in “Progress Map”
- Set the zIndex of a specific marker
- Replace/override your map query settings to showcase diverse locations on any page
- Show locations based on a keyword search
- Display “Progress Map” metabox on “Envira Gallery” add/edit page
- How to add custom class names to the infoboxes
- How to add “Read More” link to the infobox content
- Programmatically change the content of the carousel items
- Programmatically change the content of the infobox
- Programmatically change the title of the infobox
- Make the plugin GDPR/DSGVO compliance
- Trigger marker events
- Open the locations/posts “Nearby places” map inside a modal
- Redirect to the single post on marker click
- Insert a map inside a taxonomy page and display locations based on the current taxonomy term
- Use marker popups to display the post ID
- Change the text of the button “Toggle Carousel”
- Use the StreetView image as the carousel items image
- Hide the Points of Interest from the map
- Import/Export your maps between WordPress websites
- Import/Export your map locations between WordPress websites