A set of files that can be integrated into a theme to use an address custom post type and Advanced Custom Fields to populate a custom Google map.
- Advanced Custom Fields plugin
- Correctly set text domain in style.css (it should be your theme folder name)
- Your own Google Maps API key.
No particular theme is required. The folder/file structure here simply denotes where you would place the files in the current Double-E Foundation file structure. It could be adjusted for use in other themes fairly easily.
Files for all steps are included in this repo.
- Create custom post type for addresses using
functions/custom-post-types/address.php
- Call
functions/custom-post-types/address.php
andfunctions/maps/map-data.php
in your theme's functions.php - Import ACF fields (or create your own) using
acf-address-fields.json
. If you change these or create your own, you will need to edit the map builder files accordingly - Add your own Google Maps API key at the bottom of
template-parts/map.php
- Add the map to your desired template by calling
get_template_part('template-parts/map.php')
- Import
scss/theme/template-parts/_map.scss
into your style.scss - Compile CSS
- Add some addresses in WordPress and watch the magic happen!
- To change the appearance of the map, edit
functions/maps/map-style.php
. - To change the map pin icon, replace
assets/map-marker.svg
. - To change the default centre point of the map, edit the lat and long for it in
template-parts/map.php
(Line 57 at the time of writing this). - To change the inclusions and markup of the info windows that pop up when you click a pin, edit the
doublee_map_info_box
function infunctions/maps/map-data.php
. - To limit the number of addresses shown or exclude specific addresses, edit the query in the
doublee_get_address_ids()
function infunctions/maps/map-data.php
.