How to Prevent GD JavaScript from Loading on non-GD Pages in WordPress?

 
/**
* Dequeue core scripts & styles on non GD pages.
*
* Note: This may cause JavaScript errors when page contains widget/shortcode from GD.
*/
function wpsc_gd_snippet_dequeue_scripts() {
	if ( class_exists( 'GeoDir_Frontend_Scripts' ) && ! geodir_is_geodir_page() && !is_page('my-custom-page') ) {
		global $geodir_location_manager;
// GeoDirectory
remove_action( 'wp_enqueue_scripts', array( 'GeoDir_Frontend_Scripts', 'load_scripts' ) );
remove_action( 'wp_print_scripts', array( 'GeoDir_Frontend_Scripts', 'localize_printed_scripts' ), 5 );
remove_action( 'wp_print_footer_scripts', array( 'GeoDir_Frontend_Scripts', 'localize_printed_scripts' ), 5 );
// Location Manager
if ( ! empty( $geodir_location_manager ) ) {
	remove_action( 'wp_enqueue_scripts', array( $geodir_location_manager, 'add_styles' ), 10 );
	remove_action( 'wp_enqueue_scripts', array( $geodir_location_manager, 'add_scripts' ), 10 );
}
if ( class_exists( 'GeoDir_Frontend_Scripts' ) && ! geodir_is_geodir_page() && !is_front_page() ) {
	remove_action('wp_footer', array( 'GeoDir_Frontend_Scripts', 'js_location_functions' ));
	remove_action( 'wp_enqueue_scripts', array( 'GeoDir_Frontend_Scripts', 'load_scripts' ) );
	remove_action( 'wp_print_scripts', array( 'GeoDir_Frontend_Scripts', 'localize_printed_scripts' ), 5 );
	remove_action( 'wp_print_footer_scripts', array( 'GeoDir_Frontend_Scripts', 'localize_printed_scripts' ), 5 );
	remove_action('wp_footer','geodir_location_autocomplete_script');
}
}
}
add_action( 'wp', 'wpsc_gd_snippet_dequeue_scripts', 100 );

Subscribe To Our Newsletter

Join our mailing list to receive the latest news and updates from our team.

You have Successfully Subscribed!

Share This