0

I am trying to create a theme using curtains.js but am having a few problems. I have both registered and enqueued the script and the part that would go in the footer like so:

add_action('wp_enqueue_scripts', 'tf_load_custom_scripts');

function tf_load_custom_scripts() {
    wp_register_script('curtain', get_template_directory_uri().'/js/curtain.js', array('jquery'), 2.0 ); 
    wp_register_script('curtain-instance', get_template_directory_uri().'/js/curtain-instance.js', array('curtain','jquery'), true ); 

    if( is_front_page() ) {
        wp_enqueue_script('curtain');
        wp_enqueue_script('curtain-instance');
    }

    wp_enqueue_script('custom_script', get_template_directory_uri().'/js/script.js', array('jquery'), 1.0, true );

}

I've also changed all the $ to jQuery to comply with no-conflict rules.

My scripts all seem to be loading fine but not running. I'm probably missing something very obvious. Thanks in advance for any insight.

  • 2
    Have you checked the console for errors? – Mario Sep 3 '13 at 13:37
  • No errors (aside for a couple of css ones that have nothing to do with it.) – mantis Sep 3 '13 at 14:00
  • 1
    Posted code is good. (Only a tip: wp_enqueue_script('curtain'); is not needed once you registered 'curtain' as a dependence for 'curtain-instance' that is enqueued the next line) But sure problem is not this. Again, this code is good (and if all the files you enqueue are where you search for them) what causes the problem 99,99% is somewhere else. If your js code is wp-related post here, if not try asking stackoverflow. – gmazzap Sep 3 '13 at 14:23
  • I think you might be onto something. I'm compiling it using codekit and the minified file is in the wrong place but I thought that it didn't matter since I'm using the originals. I'll have to look into that. Thanks. – mantis Sep 3 '13 at 15:40
  • 1
    Is your script compatible with the version of jQuery bundled with WordPress? – Chip Bennett Sep 3 '13 at 16:08
0

WordPress-specific script issues are generally limited to one of the following:

  1. Improperly enqueued script

    Proper script enqueueing involves use of wp_enqueue_script(). If the script is properly enqueued, you will see a <script....> link in the document head or footer

  2. Not accounting for jQuery no-conflict mode

    WordPress-bundled jQuery is configured for no-conflict mode, which requires wrapping scripts in jquery(document).ready(function({})

  3. The script not being compatible with the version of jQuery bundled with WordPress

    As of WordPress 3.6, the bundled version of jQuery is 1.10.2, which is known to cause some compatibility with some outdated scripts

  • Correct for number 3 in my case. I tested it in html and fixed it there with jquery-migrate. Still having problems with the wordpress site though. Although I put trueas the last parameter my scripts are still appearing in the header. I think this might be the problem. – mantis Sep 4 '13 at 7:42
0

Have you tested the jQuery/Java script with JSfiddle? It seems like these scripts do not execute when you call them improperly. Like wrapping the script in the head, body, domready etc...

Try this jQuery(document).ready(function () { Your code here});

  • 1
    As a note, if he loads the files in the footer, he might not need to add $(document).ready() – Mario Sep 3 '13 at 13:36
  • I've tried both that and without the (document).ready. Everything works fine in html. – mantis Sep 3 '13 at 13:59

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.