Last active
October 13, 2016 07:57
-
-
Save asharirfan/0aa81890762ca4fe881b28e29a3f03f0 to your computer and use it in GitHub Desktop.
Place this function inside Real Home theme's/child theme's functions.php file. This function removes select2 JS and CSS of WooCommerce so that Real Homes theme can use its own sources of select2.
This file contains hidden or 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 | |
if ( ! function_exists( 'inspiry_fix_select2_wc' ) ) { | |
/** | |
* inspiry_fix_select2_wc. | |
* | |
* This function removes select2 JS and CSS of WooCommerce | |
* so that theme can use its own. | |
* | |
* @since 2.6.2 | |
*/ | |
function inspiry_fix_select2_wc() { | |
if ( class_exists( 'woocommerce' ) ) { | |
/** | |
* Settings for CSS optimisation | |
*/ | |
$inspiry_optimise_css = get_option( 'inspiry_optimise_css' ); | |
wp_dequeue_style( 'select2' ); | |
wp_deregister_style( 'select2' ); | |
wp_dequeue_style( 'main-css' ); | |
wp_deregister_style( 'main-css' ); | |
wp_dequeue_script( 'select2'); | |
wp_deregister_script('select2'); | |
wp_dequeue_script( 'custom'); | |
wp_deregister_script('custom'); | |
// select2 CSS | |
wp_enqueue_style( | |
'select2', | |
get_template_directory_uri() . '/js/select2/select2.css', | |
array(), | |
'4.0.2' | |
); | |
// main styles | |
if ( 'true' == $inspiry_optimise_css ) { | |
wp_enqueue_style( | |
'main-css', | |
get_template_directory_uri() . '/css/main.min.css', | |
array(), | |
INSPIRY_THEME_VERSION, | |
'all' | |
); | |
} else { | |
wp_enqueue_style( | |
'main-css', | |
get_template_directory_uri() . '/css/main.css', | |
array(), | |
INSPIRY_THEME_VERSION, | |
'all' | |
); | |
} | |
// select2 JS | |
wp_enqueue_script( | |
'select2', | |
get_template_directory_uri() . '/js/select2/select2.full.min.js', | |
array( 'jquery' ), | |
'4.0.2', | |
true | |
); | |
// Theme's main script | |
wp_register_script( | |
'custom-js', | |
get_template_directory_uri() . '/js/custom.js', | |
array( 'jquery' ), | |
INSPIRY_THEME_VERSION, | |
true | |
); | |
/* Responsive menu title */ | |
$localized_array_fix = array( | |
'nav_title' => __('Go to...','framework') | |
); | |
wp_localize_script( 'custom-js', 'localized', $localized_array_fix ); | |
/* Finally enqueue theme's main script */ | |
wp_enqueue_script( 'custom-js' ); | |
} | |
} | |
add_action( 'wp_enqueue_scripts', 'inspiry_fix_select2_wc', 100 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment