Last active
November 19, 2018 15:55
-
-
Save Willem-Siebe/c6d798ccba249d5bf080 to your computer and use it in GitHub Desktop.
Remove CSS and/or JS for Select2 used by WooCommerce, see http://stackoverflow.com/questions/28547598/how-to-unload-select2-script-styles-loaded-by-new-woocommerce-2-3-x.
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
// Remove CSS and/or JS for Select2 used by WooCommerce, see https://gist.github.com/Willem-Siebe/c6d798ccba249d5bf080. | |
add_action( 'wp_enqueue_scripts', 'wsis_dequeue_stylesandscripts_select2', 100 ); | |
function wsis_dequeue_stylesandscripts_select2() { | |
if ( class_exists( 'woocommerce' ) ) { | |
wp_dequeue_style( 'select2' ); | |
wp_deregister_style( 'select2' ); | |
wp_dequeue_script( 'select2'); | |
wp_deregister_script('select2'); | |
} | |
} |
Note that in more recent WooCommerce versions (I believe starting with 3.2 but couldn't find a hard confirmation), there is a forked version of select2 with a different name: selectWoo. So the code would then be:
// Remove CSS and/or JS for Select2 used by WooCommerce, see https://gist.github.com/Willem-Siebe/c6d798ccba249d5bf080. add_action( 'wp_enqueue_scripts', 'wsis_dequeue_stylesandscripts_select2', 100 ); function wsis_dequeue_stylesandscripts_select2() { if ( class_exists( 'woocommerce' ) ) { wp_dequeue_style( 'selectWoo' ); wp_deregister_style( 'selectWoo' ); wp_dequeue_script( 'selectWoo'); wp_deregister_script('selectWoo'); } }
This is the working code till today with latest woo version (19/11/2018 - Woo Ver: 3.5.1)
Sometimes "Select2" dont render in first page load, giving to the user a simple text field ... so I am going to sidable it in each of my new projects.
Thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes! @eversionsystems, thanks for the tip, this code worked for me:
I had a site running WooCommerce v2.6 and ACF Pro was failing because it was getting an old version of Select2 supplied to it. Adding this snippet to my functions.php removed it before ACF tried to add its own so it is now working!