0
votes

I am trying to load a js file on a page, I've included

function formScriptLoad() {
  wp_enqueue_script( 'formScript', get_template_directory_uri() . 'https://tmsact.com.au/wp-content/themes/hello-elementor/assets/js/formScript.js');
}
add_action('wp_enqueue_scripts','formScriptLoad');

in the functions.php of the theme I'm using and I checked that header.php and footer.php have a wp_head() and wp_footer() included. Any idea what I might be missing? Thanks!

EDIT: when I paste the script directly on the page using < script > in a HTML embed it works briefly then stops on refresh.

1
wp_enqueue_script( 'formScript', get_template_directory_uri() . '/assets/js/formScript.js');MattHamer5
Thanks! that partly fixed it. Another thing I was doing wrong was placing the script before the HTML and CSS. Moved it after and it works fine!Ste

1 Answers

0
votes

Remove get_template_directory_uri() . part and try again; that is an absolute path, not a relative one, so you do not need to add it.

Example: