I need to exclude GD scripts for non-gd-pages

This topic contains 3 replies, has 2 voices, and was last updated by  Kiran 4 years, 5 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket

Tagged: 

  • Author
    Posts
  • #517613

    filisara
    Buyer
    Post count: 4

    ref: https://wpgeodirectory.com/support/topic/who-to-exclude-gd-js-script-from-same-pages/#post-406458

    Hi!
    as I asked for GD v1 I’m here to renew my old question about GD v2.
    I have to exclude all GD functions for non-GD-pages.
    The function you gave me doesn’t work anymore.

    thanks!
    SF

    #517644

    Kiran
    Moderator
    Post count: 7069

    Hi filisara,

    Please try following PHP snippet for GDv2.

    
    
    /**
     * 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() ) {
    		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 );
    		}
    	}
    }
    add_action( 'wp', 'gd_snippet_dequeue_scripts', 100 );

    Regards,
    Kiran

    #517949

    filisara
    Buyer
    Post count: 4

    Hi Kiran,
    thanks for your support!

    it works! but I use Location Manager Plugin also and I have geodir-location.css that is loaded on all pages.

    do you please tell me the correct line to add to the function to esclude script/css of this plugin?

    thanks!

    #518098

    Kiran
    Moderator
    Post count: 7069

    Hi filisara,

    I have updated snippet to dequeue Location Manager scripts. Please copy and update snippet on your site.

    Regards,
    Kiran

Viewing 4 posts - 1 through 4 (of 4 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket