Skip to content

Instantly share code, notes, and snippets.

@asharirfan
Last active February 19, 2018 14:40
Show Gist options
  • Save asharirfan/eeb251dae78fcde27c1321b6036befd4 to your computer and use it in GitHub Desktop.
Save asharirfan/eeb251dae78fcde27c1321b6036befd4 to your computer and use it in GitHub Desktop.
This function removes select2 JS and CSS of WooCommerce so that theme can use its own.
<?php
if ( ! function_exists( 'remove_select2_wc' ) ) {
/**
* remove_select2_wc.
*
* This function removes select2 JS and CSS so that
* theme can use its own.
*/
function remove_select2_wc() {
if ( class_exists( 'woocommerce' ) ) {
wp_dequeue_style( 'select2' );
wp_deregister_style( 'select2' );
wp_dequeue_style( 'your-theme-main-css-file' );
wp_deregister_style( 'your-theme-main-css-file' );
wp_dequeue_script( 'select2');
wp_deregister_script('select2');
wp_dequeue_script( 'your-theme-js-file');
wp_deregister_script( 'your-theme-js-file' );
// select2 CSS
wp_enqueue_style(
'select2',
get_template_directory_uri() . 'path-to-select2-css',
array(),
'1.0.0'
);
// main styles
wp_enqueue_style(
'your-theme-main-css-file',
get_template_directory_uri() . 'path-to-your-theme-main-css-file',
array( 'select2' ),
1.0.0
);
// select2 JS
wp_enqueue_script(
'select2',
get_template_directory_uri() . 'path-to-select2-js',
array( 'jquery' ),
'1.0.0',
true
);
// Main js
wp_enqueue_script(
'your-theme-js-file',
get_template_directory_uri() . 'path-to-your-theme-js-file',
array( 'jquery', 'select2' ),
1.0.0,
true
);
}
}
add_action( 'wp_enqueue_scripts', 'remove_select2_wc', 100 );
}
@PogHallam
Copy link

Looks like there might be some quotes missing on lines 37 and 54.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment