function child_script() { wp_dequeue_script( 'ct-fullwidth-optimizer' ); wp_enqueue_script('ct-fullwidth-optimizer', get_stylesheet_directory_uri() . '/js/ct-fullwidth-loader.js', false, false, false); wp_dequeue_script( 'ct-scripts' ); wp_enqueue_script('ct-scripts', get_stylesheet_directory_uri() . '/js/functions.js', array('jquery', 'ct-form-elements', 'odometr', 'ct-sticky', 'jquery-dlmenu'), false, true); } add_action('wp_enqueue_scripts', 'child_script', 9999); 

The parent has an app.js file. Can I create my own app.js file in the child thread so that it interrupts the previous one? that is, it will not even load but will be taken from the child theme? Added the first version of the code, nothing has changed. Then I tried version 2 of the code and the scripts just stopped working. They will not connect with a child thread.

 add_action( 'wp_print_scripts', 'de_script', 100 ); function de_script() { wp_dequeue_script( 'ct-fullwidth-optimizer' ); wp_deregister_script( 'ct-fullwidth-optimizer' ); wp_dequeue_script( ' ct-scripts' ); wp_deregister_script( ' ct-scripts' ); } 

  • one
    It is necessary to cancel the launch of the script from the parent theme. Here I wrote how to do it: ru.stackoverflow.com/questions/822164/… . And then run your script in the child theme. - KAGG Design
  • See there something like this function name {wp_enqueue_script (1 .....); wp_enqueue_script (2 .......); wp_enqueue_script (3 ....); ..... wp_enqueue_script (10 ...); } add_action ('wp_enqueue_scripts', 'name'); If I add a filter, all scripts can be disabled, can I select 1? - Vlad467
  • We would immediately post the script launch code, which should be canceled, right in the question - we would get rid of the extra correspondence. - KAGG Design

1 answer 1

When many scripts are launched by a single function, you cannot cancel a share - all will be canceled. It is necessary so:

In the child theme in functions.php write

 function add_child_scripts() { wp_dequeue_script( 'script_1' ); wp_enqueue_script('script_1', $script_url, array(...) ); } add_action( 'wp_enqueue_scripts', 'add_child_scripts', 9999 ); 

add_child_scripts should run later than the equivalent in the parent theme (see 9999). dependency (array (...)) must be the same as in the parent theme.

  • something does not come out. I added the code as I did - Vlad467
  • Where is the app.js file in question? Put it in order. Spread the version of my answer there is not necessary. - KAGG Design