J
J
John2016-04-20 13:13:41
PHP
John, 2016-04-20 13:13:41

Custom scripts in WP child theme?

I include a regular JS file in the child theme, my functions.php file looks like this:

<?php 
    function theme_js() {
        wp_enqueue_script( 'theme_js', get_template_directory_uri() . '/js/custom.js', array( 'jquery' ), '1.0', true );
    }
    
    add_action('wp_enqueue_scripts', 'theme_js');
?>

But what happens is that WP finds the custom.js file from the parent theme. Why is this even happening?
If I change the path and the structure of the path to the file (to be sure to take it from the child theme), then it is not found at all
wp_enqueue_script( 'theme_js', get_template_directory_uri() . '/js/custom/custom.js', array( 'jquery' ), '1.0', true );

In general, how to do it all right? Why doesn't WP itself determine to take the overridden JS file from the child theme, as it does with all other files?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dvoeglazov, 2018-08-15
@Dvoeglazov

Perhaps you need to connect the script file of the parent theme at the beginning, and then add your own to array, depending on the parent file.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question