Site icon Anthony Carbon

WordPress register / deregister script / in wp_head.

To replace the default WordPress jquery ( http://192.185.73.118/~anthonycarbon/wp-includes/js/jquery/jquery.js ) library with the Google hosted jquery library, copy the below codes and paste it into your functions.php file.

The7 WordPress theme dequeue script. Example is `dt-above-fold`.

add_action( 'wp_enqueue_scripts', 'my_deregister_javascript', 20 );
add_action( 'wp_print_scripts', 'wp_print_scripts_deregister', 100 );
function my_deregister_javascript() {
    if ( ! is_admin() && isset( $_GET['wp_print_scripts'] ) ){
        wp_deregister_script( 'dt-above-fold' );
        wp_dequeue_script( 'dt-above-fold' );
    }
}
function front_end_default_jquery_library() {
    global $wp_scripts, 
    if ( !is_admin( ) ){ 
        wp_deregister_script('jquery');
        wp_register_script( 'jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/'.$version.'/jquery.min.js', false, $version );
        wp_enqueue_script('jquery');
    }
}
add_action( 'init', 'front_end_default_jquery_library' );

How to deregister a script on wp_head section ? In my example below, i have to deregister the contact form 7 script in my wp_head section. To do that, copy the code and paste it into your functions.php file. To determine the registered script name, you have to open the core of your plugin and look for script name, or search on the internet.

add_action( 'wp_print_scripts', 'my_deregister_javascript', 100 );
function my_deregister_javascript() {
    wp_deregister_script( 'contact-form-7' );
}

How to remove contact form 7 styles on wp_head section? The code below is the solutions of your problem. To do that, copy the code and paste it into your functions.php file.

add_action( 'wp_print_styles', 'my_deregister_styles', 100 );  
function my_deregister_styles() {
    wp_deregister_style( 'contact-form-7' ); //  
}

Codes below is to register a scripts and style sheets on your wp_head section.

add_action( 'wp_enqueue_scripts', 'my_wp_head_injection' );
function my_wp_head_injection() { 
	if( !is_admin() ){
		wp_register_style( 'style-custom', get_stylesheet_directory_uri() . '/style-custom.css' );
		wp_enqueue_style( 'style-custom' );
		wp_register_style( 'style-responsive', get_stylesheet_directory_uri() . '/style-responsive.css' );
		wp_enqueue_style( 'style-responsive' ); 
	  	wp_register_script( 'general-script', get_stylesheet_directory_uri() . '/js/general-script.js' ); 
	  	wp_enqueue_script( 'general-script' );
	  	wp_register_script( 'responsive-menu', get_stylesheet_directory_uri() . '/js/responsive-menu.js' ); 
	  	wp_enqueue_script( 'responsive-menu' );
	}
}

Woocommerce script

wc-price-slider 
wc-add-to-cart
chosen
jquery-placeholder
wc-add-to-cart-variation
wc-single-product
jquery-cookie
wc-cart
wc-chosen
woocommerce_chosen_styles
wc-checkout
woocommerce
Exit mobile version