0

I would like to include a custom jQuery script for a Child Theme within WordPress. I am using the script below in my function.php file within my WP Child Theme folder / directory.

The problem is the script is attaching it to the parent theme within url. For Example it is outputting

localhost:8888/wordpress/wp-content/themes/responsive/custom_js/footer.js

when it should be

localhost:8888/wordpress/wp-content/themes/responsive-childtheme-master/custom_js/footer.js

<?
function jerrell_adds_to_the_footer(){

    wp_register_script('add-footer-js', get_template_directory_uri() . '/custom_js/jquery_test.js', array('jquery'),'', true );

    wp_enqueue_script('add-footer-js');

}

    add_action('wp_enqueue_scripts', 'jerrell_adds_to_the_footer'); //Hooks my custom function into WP's wp_enqueue_scripts function
    ?>

2 Answers 2

1

get_stylesheet_directory_uri() should return the child theme's directory while get_template_directory_uri() returns the parent's.

Sign up to request clarification or add additional context in comments.

Comments

1

since you are using a child theme, you should use get_stylesheet_directory_uri() instead of get_template_directory_uri()

<?
function jerrell_adds_to_the_footer(){

wp_register_script('add-footer-js', get_stylesheet_directory_uri() . '/custom_js/jquery_test.js', array('jquery'),'', true );

wp_enqueue_script('add-footer-js');

}

add_action('wp_enqueue_scripts', 'jerrell_adds_to_the_footer'); //Hooks my custom     function into WP's wp_enqueue_scripts function
?>

Comments

Your Answer

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