Anokrize Anokrize - 2 months ago 13
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

FormScript.js
and is located here:

/httpdocs/wp-content/themes/Avada/FormScript.js


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...

Answer

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');

Edit:
From the documentation:

Note: Does not contain a trailing slash.