Support » Plugin: WP GPX Maps » register, enqueue styles and script

  • Is it possible to register and enqueue the scripts and styles of the plugin only when shortcode is present?

    I’m also using the plugin leaflet-map and there is a conflict between your plugin and leaflet-map. I wrote my own functions for that, but it would be better if it were in the plugin.

    Thank you.

Viewing 2 replies - 1 through 2 (of 2 total)
  • A big +1 for this!
    @hupe13 could you share the functions you wrote?

    Thread Starter hupe13

    (@hupe13)

    Put this in the function.php of your theme. If you need the Photo function comment out lines in the add_filter function.

    <?php
    function dequeue_sgpx(){
    	wp_dequeue_script('leaflet');
    	wp_dequeue_style('leaflet.fullscreen');
    	wp_dequeue_style('leaflet');
    	wp_dequeue_style('leaflet.markercluster');
    	wp_dequeue_script('leaflet.markercluster');
    	wp_dequeue_style('leaflet.Photo');
    	wp_dequeue_script('leaflet.Photo');
    	wp_dequeue_script('leaflet.fullscreen');
       	wp_dequeue_script('WP-GPX-Maps');
    	wp_dequeue_script('chartjs');
    	wp_deregister_script('leaflet');
    	wp_deregister_style('leaflet.fullscreen');
    	wp_deregister_style('leaflet');
    	wp_deregister_style('leaflet.markercluster');
    	wp_deregister_script('leaflet.markercluster');
    	wp_deregister_style('leaflet.Photo');
    	wp_deregister_script('leaflet.Photo');
    	wp_deregister_script('leaflet.fullscreen');
       	wp_deregister_script('WP-GPX-Maps');
    	wp_deregister_script('chartjs');
    	remove_action('wp_print_styles', 'print_WP_GPX_Maps_styles' );
    }
    
    function dequeue_all_sgpx(){
    	dequeue_sgpx();
    }
    add_action( 'wp_enqueue_scripts', 'dequeue_all_sgpx' , 100);
    
    // Enqueue if shortcode exists
    add_filter('pre_do_shortcode_tag', function ( $output, $shortcode ) {
    	if ( 'sgpx' == $shortcode ) {
    		enqueue_WP_GPX_Maps_scripts();
    		wp_dequeue_style('leaflet.Photo');
    		wp_dequeue_script('leaflet.Photo');
        }
    	return $output;
    }, 10, 2);
    
    ?>
    
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘register, enqueue styles and script’ is closed to new replies.