Title: register, enqueue styles and script
Last modified: January 10, 2020

---

# register, enqueue styles and script

 *  [hupe13](https://wordpress.org/support/users/hupe13/)
 * (@hupe13)
 * [6 years, 4 months ago](https://wordpress.org/support/topic/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](https://wordpress.org/support/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)

 *  [techtimo](https://wordpress.org/support/users/techtimo/)
 * (@techtimo)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/register-enqueue-styles-and-script/#post-12954732)
 * A big +1 for this!
    [@hupe13](https://wordpress.org/support/users/hupe13/) could
   you share the functions you wrote?
 *  Thread Starter [hupe13](https://wordpress.org/support/users/hupe13/)
 * (@hupe13)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/register-enqueue-styles-and-script/#post-12955079)
 * 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.

 * ![](https://s.w.org/plugins/geopattern-icon/wp-gpx-maps_bcbfb3.svg)
 * [WP GPX Maps](https://wordpress.org/plugins/wp-gpx-maps/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-gpx-maps/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-gpx-maps/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-gpx-maps/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-gpx-maps/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-gpx-maps/reviews/)

## Tags

 * [enqueue](https://wordpress.org/support/topic-tag/enqueue/)
 * [register](https://wordpress.org/support/topic-tag/register/)

 * 2 replies
 * 2 participants
 * Last reply from: [hupe13](https://wordpress.org/support/users/hupe13/)
 * Last activity: [5 years, 11 months ago](https://wordpress.org/support/topic/register-enqueue-styles-and-script/#post-12955079)
 * Status: not resolved