vendredi 6 février 2015

I want to enqueue a .js file to my child theme


I tried to enqueue a custom .js file in my child theme directory.


In the functions.php of my child theme I find the following code



/* After this. you can override Accessible Zen's pluggable functions or add your own.
* Remember, do your best to stay accessible! :)
*
*/
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
wp_enqueue_script( 'custom-script.js', 'js/custom-script.js', array('jquery') );
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-style', get_stylesheet_uri(), array( 'parent-style' ) );
}


where only this part was implemented by me and is supposed to load my custom.script.js from the js/ folder



wp_enqueue_script( 'custom-script.js', 'js/custom-script.js', array('jquery') );


Unfortunately it doesn't do so, can anybody help?


*Update 2


The Code looks now like this and it works, it did not work when I just added the function to the other add_action. Thanks everybody for the help! Still I wonder if there isnt a way to cut this code a little bit.



add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-style', get_stylesheet_uri(), array( 'parent-style' ) );
}

/*add my custom jquery script*/
add_action( 'wp_enqueue_scripts', 'menu_scripts' );
function menu_scripts() {
wp_enqueue_script( 'responsive-menu', get_bloginfo( 'stylesheet_directory' ) . '/js/responsive-menu.js', array( 'jquery' ), '1.0.0' );
wp_enqueue_script(
'custom-script',
get_stylesheet_directory_uri() . '/js/custom-script.js',
array( 'jquery' )
);
}


What is this line for ?



wp_enqueue_script( 'responsive-menu', get_bloginfo( 'stylesheet_directory' ) . '/js/responsive-menu.js', array( 'jquery' ), '1.0.0' );


Is it necessary?





Aucun commentaire:

Enregistrer un commentaire