directory structure issue when calling a JS file and Ajax

Question

I can not seem to make the call to the proper JS file location despite trying everything that I can think of. Below is the way that it should be from everything I know to find that “myjsfile.js” (name replaced for stackoverflow)

function my_scripts() {   
wp_enqueue_script( 'myscript', get_theme_file_uri( '/assets/js/myjsfile.js' ), array('jquery'), null, true );
wp_localize_script('myscript', 'my_ajax', array('ajax_url' => admin_url('admin-ajax.php')));
}
add_action('wp_enqueue_scripts', 'my_scripts');

My file I am trying to call is located in https://mywebsite.com/wp-content/themes/”mytheme”/assets/js. The above PHP script is located in https://mywebsite.com/wp-content/themes/”mytheme”

I have tried:

'/assets/js/myjsfile.js'
'../assets/js/myjsfile.js'
'../../assets/js/myjsfile.js'
'"mytheme"/assets/js/myjsfile.js'
'themes/"mytheme"/assets/js/myjsfile.js'
'../themes/"mytheme"/assets/js/myjsfile.js'
'../../themes/"mytheme"/assets/js/myjsfile.js'
'wp-content/themes/"mytheme"/assets/js/myjsfile.js'
'/wp-content/themes/"mytheme"/assets/js/myjsfile.js'
'../wp-content/themes/"mytheme"/assets/js/myjsfile.js'

all with no luck. By default ‘/assets/js/myjsfile.js’ doesnt call the JS file but instead calls /wp-admin/admin-ajax.php . The other exxamples above all call some version of https://mywebsite.com/wp-content/themes/”mytheme”/themes/”mytheme”/assets/js and simply add to the proper directory structure whatever I have placed in front of the /assets/js/myjsfile.js. It doubles it. Can anyone point out where I seem to be going wrong here?

0
Theodore 4 months 0 Answers 15 views 0

Leave an answer