cliff
9/14/2016 - 8:18 PM

Do not load https://optimizerwp.com/optimizer-pro/ theme's Google Maps script on The Events Calendar (TEC) pages, except for Post Tags, then

Do not load https://optimizerwp.com/optimizer-pro/ theme's Google Maps script on The Events Calendar (TEC) pages, except for Post Tags, then do not load TEC's

<?php

/**
  * Do not load https://optimizerwp.com/optimizer-pro/ theme's Google Maps script on The Events Calendar (TEC) pages, except for Post Tags, then do not load TEC's
  *
  * From https://gist.github.com/cliffordp/ca3baf77c9be8b72f37db10c7c91783b
  *
  * For https://theeventscalendar.com/support/forums/topic/errors-you-have-included-the-google-maps-api-multiple-times-on-this-page/
  */
function tec_1163154_dequeue_gmaps_script() {
	if ( ! class_exists( 'Tribe__Events__Main' ) ) {
		return false;
	}
	
	$tecmain = Tribe__Events__Main::instance();
	
	if (
		// https://developer.wordpress.org/reference/functions/is_post_type_archive/
		is_post_type_archive( $tecmain::POSTTYPE )
		|| is_post_type_archive( $tecmain::VENUE_POST_TYPE )
		|| is_post_type_archive( $tecmain::ORGANIZER_POST_TYPE )
		// https://developer.wordpress.org/reference/functions/is_singular/
		|| is_singular( $tecmain::POSTTYPE )
		|| is_singular( $tecmain::VENUE_POST_TYPE )
		|| is_singular( $tecmain::ORGANIZER_POST_TYPE )
		// https://developer.wordpress.org/reference/functions/is_tax/
		|| is_tax( $tecmain::TAXONOMY )
	) {
		wp_dequeue_script( 'optimizer_googlemaps' );
		// Maybe also do this next one too? If yes, uncomment it.
		// wp_dequeue_script( 'optimizer_map' );

	}
	
	if (
		// https://developer.wordpress.org/reference/functions/is_tag/
		is_tag()
	) {
		wp_dequeue_script( 'tribe_events_google_maps_api' );
	}
}
add_action( 'wp_print_scripts', 'tec_1163154_dequeue_gmaps_script', 100 );