Skip to content

Instantly share code, notes, and snippets.

@jmabbas
Created September 10, 2026 07:16
Show Gist options
  • Select an option

  • Save jmabbas/a3975b49e1326f7da6e65fdbbea2ae4e to your computer and use it in GitHub Desktop.

Select an option

Save jmabbas/a3975b49e1326f7da6e65fdbbea2ae4e to your computer and use it in GitHub Desktop.
GoTrek - Single product Maps URL
function gotrek_single_hotel_show_map() {
if ( ! gotrek_is_acf_activated() ) {
return;
}
$hotel_group = gotrek_get_hotel_group();
if ( ! empty( $hotel_group['location_map'] ) ) :
$map_url = '';
if ( is_array( $hotel_group['location_map'] ) ) {
if ( ! empty( $hotel_group['location_map']['address'] ) ) {
$map_url = 'https://maps.google.com/maps?q=' . rawurlencode( $hotel_group['location_map']['address'] );
} elseif ( ! empty( $hotel_group['location_map']['lat'] ) && ! empty( $hotel_group['location_map']['lng'] ) ) {
$map_url = 'https://maps.google.com/maps?q=' . rawurlencode( $hotel_group['location_map']['lat'] . ',' . $hotel_group['location_map']['lng'] );
}
} elseif ( is_string( $hotel_group['location_map'] ) ) {
$location_map = trim( $hotel_group['location_map'] );
if ( ! empty( $location_map ) ) {
if ( preg_match( '/^(https?:\/\/|\/\/)/i', $location_map ) ) {
$map_url = $location_map;
} else {
$map_url = 'https://maps.google.com/maps?q=' . rawurlencode( $location_map );
}
}
}
if ( ! empty( $map_url ) ) :
?>
<a href="<?php echo esc_url( $map_url ); ?>" data-src="#hotel-map" data-speed="700" class="single_hotel_show_map">
<img class="img-fluid" src="<?php echo esc_url( get_template_directory_uri() . '/assets/images/map.svg' ); ?>" alt="<?php esc_attr_e( 'Map-Image', 'gotrek' ); ?>">
</a>
<?php
endif;
endif;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment