McDiamund McDiamund - 1 month ago 13
Javascript Question

I am having trouble applying javascript to wordpress

I am having trouble applying javascript with a dependency of jQuery on my wordpress site, The css function worked but not the javascript function. Any tips or help?

http://minecraftserverzz.com/youtube/

function wp_chiquedesigns_styles() {

wp_enqueue_style( 'style_css', get_template_directory_uri() . '/style.css' );

}

add_action( 'wp_enqueue_scripts', 'wp_chiquedesigns_styles' );

function chiquedesigns_child_scripts() {

wp_enqueue_script( 'main js', get_stylesheet_directory_uri() . '/main.js', array( 'jquery' ), true);

}

add_action( 'wp_enqueue_scripts', 'wp_chiquedesigns_child_scripts' );

Answer
wp_enqueue_script( 'main js', get_stylesheet_directory_uri() . '/main.js', array( 'jquery' ), true);

The above code is producing the following path:

http://minecraftserverzz.com/youtube/wp-content/themes/Chique%20Designs.zip/js/main.js

Which is a 404 - file does not exist.

get_stylesheet_directory_uri() returns the following string.

http://minecraftserverzz.com/youtube/wp-content/themes/Chique%20Designs.zip/js

It looks like your main.js file is in the folder level above that. Try moving your main.js file into the js folder