Skip to content

Instantly share code, notes, and snippets.

@1naveengiri
Last active January 11, 2023 16:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 1naveengiri/ab3870be0aafbbc9af1b35297d829685 to your computer and use it in GitHub Desktop.
Save 1naveengiri/ab3870be0aafbbc9af1b35297d829685 to your computer and use it in GitHub Desktop.
Remove Geodirectory scripts and style from non GD pages
<?php
/**
* Dequeue core scripts & styles on non GD pages.
*
* Note: This may cause JavaScript errors when page contains widget/shortcode from GD.
*/
function wpdocs_dequeue_script() {
if ( class_exists( 'AyeCode_UI_Settings' ) && ! geodir_is_geodir_page() && !is_page('piano-bars') && !is_page('piano-lessons') && !is_page('piano-movers') && !is_page('piano-tuners') && !is_front_page() && !is_page('piano-bars') && !is_page('piano-lessons') && !is_page('piano-movers') && !is_page('piano-tuners') && wp_get_post_parent_id( get_the_ID() ) != 2886 ) {
wp_dequeue_script( 'bootstrap-js-bundle' );
wp_dequeue_style( 'ayecode-ui' );
wp_dequeue_script( 'geodir-cp-widget' );
wp_dequeue_style( 'geodir-cp-widget' );
}
}
add_action( 'wp_enqueue_scripts', 'wpdocs_dequeue_script' );
add_action( 'wp_print_scripts', 'wpdocs_dequeue_script', 100 );
function gd_snippet_dequeue_scripts2() {
if ( class_exists( 'GeoDir_Frontend_Scripts' ) && !geodir_is_geodir_page() && !is_page('piano-bars') && !is_page('piano-lessons') && !is_page('piano-movers') && !is_page('piano-tuners') && !is_front_page() && !is_page('piano-bars') && !is_page('piano-lessons') && !is_page('piano-movers') && !is_page('piano-tuners') && wp_get_post_parent_id( get_the_ID() ) != 2886 ) {
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 );
remove_action('wp_footer','geodir_location_autocomplete_script');
remove_action('wp_footer','geodir_advanced_search_autocomplete_script');
remove_filter( 'wp_footer' , 'geodir_search_form_add_script' , 10 );
}
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 );
}
}
add_action( 'wp', 'gd_snippet_dequeue_scripts2', 100 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment