質問

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
    ?>
役に立ちましたか?

解決

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

他のヒント

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
?>
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top