0

I am trying to remove some script files added by wordpress. However, the code I wrote does not work. Where am I doing wrong? Can you show me the way?

I looked at many sources. But I couldn't find an answer for the ui. I have used the wp_dequeue_script function many times. But it doesn't work for Wordpress.

child theme function.php

add_action( 'wp_enqueue_scripts', 'a_remove_some_js'); 
function a_remove_some_js() { 
     //wp_dequeue_script( 'jquery-ui-core-js');
    //wp_dequeue_script( 'jquery-ui-tooltip-js');
    wp_dequeue_script( 'jquery-ui-core');
    wp_dequeue_script( 'jquery-ui-tooltip');
}

2 Answers 2

1

The related library is registered with a function called wp_default_scripts. File location (for Wordpress 6.0): ...wp-includes/script-loader.php remove to remove the relevant script; The add function is used to add a new script.

/**
 * Assigns default styles to $styles object.
 *
 * Nothing is returned, because the $styles parameter is passed by reference.
 * Meaning that whatever object is passed will be updated without having to
 * reassign the variable that was passed back to the same value. This saves
 * memory.
 *
 * Adding default styles is not the only task, it also assigns the base_url
 * property, the default version, and text direction for the object.
 *
 * @since 2.6.0
 *
 * @global array $editor_styles
 *
 * @param WP_Styles $styles
 */


add_action( 'wp_default_scripts', 'remove_js_ui_library' );
function remove_js_ui_library( &$scripts){
    if(!is_admin()){
        $scripts->remove( 'jquery-ui-core');
}

}

0

It is add_action, not a filter hook - @ddisdevelpgelis

You added it as a filter hook in below code

add_filter( 'wp_default_scripts', 'remove_js_ui_library' );
function remove_js_ui_library( &$scripts){
    if(!is_admin()){
        $scripts->remove( 'jquery-ui-core');
    }
}

My changes to the above code :

add_action( 'wp_default_scripts', 'remove_js_ui_library' );
function remove_js_ui_library( &$scripts){
    if(!is_admin()){
        $scripts->remove( 'jquery-ui-core');
    }
}

Checkout this link for more information - wp_default_scripts

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.