0

I have a mysterious problem - the script file isn't loaded. The same code works on a test server. But when we uploaded it to the live server and looking at the browser console at "sources", it didn't show up at first. But for a while it did show up , but now it doesn't.

I enqueue the js-file in functions.php:

if( is_page_template( 'page-anmalan-adelsmote.php' ) || is_page_template( 'page-anmalan-slutmote.php' ) ){
        wp_register_script('form', get_template_directory_uri() . '/js/form.js', array('jquery'), '1.0.0');
        wp_enqueue_script('form');  

    }

Edit: I have put this code in the load_header_scripts(). And it is hooked like this:

add_action('wp_enqueue_scripts', 'load_header_scripts'); 

Edit2 It works if I remove the "if" condition , and just put it in the load header scripts-function:

wp_register_script('form', get_template_directory_uri() . '/js/form.js', array('jquery'), '1.0.0');
wp_enqueue_script('form');

So, what's wrong with the if condition? (it works in the test version as I said).

The file is of course in the "js"-folder right under the theme folder. The page in question has a template loaded in frontend which is the "page-anmalan-slutmote.php" template.

And the js-file is called "form.js".

There are some issues with "mixed content" where http is mixed with https-content, but in this case I don't think it should have anything to do with it. There are no console errors except "mixed content" and some error with a slider (not related). Do you have any suggestions as to what the problem may be?

  • Why are you saying that the stylesheet doesn't load in the title but are talking about loading a javascript file in the question body? – s_ha_dum Dec 3 '15 at 14:48
  • It's a script file, I was confused.. – Galivan Dec 3 '15 at 14:56
  • What doesn't "not loading" mean? The script tag doesn't appear in the source of the page? The URL is incorrect? The script doesn't work? What? – s_ha_dum Dec 3 '15 at 15:03
  • I mean that a correctly included file is "loaded" by the browser, so it is loaded (accessible, available, included). This can be tested by placing an "alert()" in a document ready function inside the js-file - which I have, but it isn't executed because the file isn't loaded. What term would you use instead of "loaded"? (edit: I edit the message so it becomes clearer that it is a js-file, not just a script tag) – Galivan Dec 3 '15 at 15:24
  • 1
    load_header_scripts() is not a function from WordPress, so we can not know what it does or when it is executed. Can you verify if it is executed on wp_enqueue_scripts action. – cybmeta Dec 3 '15 at 15:33

Your Answer

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

Browse other questions tagged or ask your own question.