How to Prevent GD JavaScript from Loading on non-GD Pages?
At times, you might not need GeoDirectory JavaScript to load on certain pages of your site. For example, you may have blog posts or sections of your site with custom styles and JS. In such cases, it is preferable to prevent GeoDirectory JavaScript from loading on such pages.
You can use the following Code Snippet to accomplish this:
/** * Dequeue core scripts & styles on non GD pages. * * Note: This may cause JavaScript errors when page contains widget/shortcode from GD. */ function 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', 'gd_snippet_dequeue_scripts', 100 );