Anokrize Anokrize - 8 months ago 45
Javascript Question

Wordpress script not loading

I am having a wordpress website and some custom javascript. However my goal is to load this javascript file the right away as wordpress is suggesting it. Somehow this is not working or I am doing something wrong.
The file is called

and is located here:


In the same directory is my function.php, in which I want to load the script.

This is how I am doing it:

if (!is_admin()) add_action("wp_enqueue_scripts", "my_jquery_enqueue", 11);
function my_jquery_enqueue() {

// Register and Enqueue a Script
// get_stylesheet_directory_uri will look up child theme location
wp_register_script( 'FormScript', get_stylesheet_directory_uri() . 'FormScript.js');
wp_enqueue_script( 'FormScript' );

But why is this not working? Thanks for help...


You are missing a / after get_stylesheet_directory_uri() inside wp_register_script.
It should be:

wp_register_script( 'FormScript', get_stylesheet_directory_uri() . '/FormScript.js');

From the documentation:

Note: Does not contain a trailing slash.