-2

I have problem with loading my own javascript file, this problem is only on home page, on other pages it's ok.

Right now I've problem with interactivity, because only on homepage I can't do that.

Inside functions.php I've included my own script using this way:

    function monaco_assets_js(){

    wp_enqueue_script('script', get_stylesheet_directory_uri() . '../js/script.js', array('jquery'), '1.0.0', true);
}
add_action('wp_enqueue_scripts', 'monaco_assets_js');
  • What do you mean by, on other pages it's ok? – bravokeyl Dec 16 '17 at 3:48
  • only for home page not working, for other pages for example in navigation I have: Home, About, Gallery, Contact. It works fine for About, Gallery and Contact. – RS92 Dec 16 '17 at 10:21
  • May I know the site URL? – bravokeyl Dec 16 '17 at 12:57
  • it's on local host – RS92 Dec 16 '17 at 17:47
0

This might be because of two issues:

  1. Unique handler is not used to enqueue scripts on homepage
  2. Path to the file is wrong

Unique Handler

You should use unique script handler while enqueuing scripts or styles using wp_enqueue_*, I see that you used script as your script handler which is pretty generic and is not recommended. If you have used the same handler for one or more scripts, only the first script will be enqueued, the other ones will be ignored.

Path to script

get_stylesheet_directory_uri() . '../js/script.js' this path goes to a parent directory of current theme and looks for js folder which I think seems to be wrong, do you have the script file there?

  • Hm I don't know what to say, I don't understand you. Look there is my functions.php: pastebin.com/vr0yFzs3 On other pages work fine, but only for homepage doesn't – RS92 Dec 16 '17 at 10:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.