Created
July 31, 2020 12:17
-
-
Save webdados/3555b4ded271fba3bfe6db0dc1437339 to your computer and use it in GitHub Desktop.
Remove WordPress unnecessary scripts and styles that some shortcodes load on every page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'wp_enqueue_scripts', 'my_remove_unnecessary_scripts_and_styles', PHP_INT_MAX ); | |
function my_remove_unnecessary_scripts_and_styles() { | |
//Remove Mapbox styles and scripts | |
global $post; | |
if ( ! ( is_a( $post, 'WP_Post' ) && has_shortcode( $post->post_content, 'wp_mapbox_gl_js' ) ) ) { | |
wp_dequeue_style( 'mapbox_gl_js_css' ); | |
wp_dequeue_style( 'mapbox_gl_js_geocoder_css' ); | |
wp_dequeue_style( 'mapbox_gl_js_directions_css' ); | |
wp_dequeue_style( 'wp-mapbox-gl-js' ); | |
wp_dequeue_script( 'mapbox_gl_js' ); | |
wp_dequeue_script( 'mapbox_gl_geocoder_js' ); | |
wp_dequeue_script( 'mapbox_gl_directions_js' ); | |
wp_dequeue_script( 'wp-mapbox-gl-js' ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment