directory structure issue when calling a JS file and Ajax


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”mytheme”/assets/js. The above PHP script is located in”mytheme”

I have tried:


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”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?

Theodore 4 months 0 Answers 15 views 0

Leave an answer