0

For some reason, the following is not loading my JS and CSS into wordpress. This code is in an activated plugin, which is otherwise executing. Also, I checked and wp_head does exist in the theme.

add_action ( 'wp_head', 'lbIncludes');

function lbIncludes()  {
    wp_enqueue_script('jquery');

    wp_register_script('myScript',
    WP_PLUGIN_URL . '/myScript/myScript.bundle.js' );
    wp_enqueue_script('myScript');

    wp_register_style('myStyle', WP_PLUGIN_URL . '/myScript/myScript.css');
    wp_enqueue_style('myStyle');
};

Bonus question - what's the appropriate way to make the script wait for jquery to load first?

2
  • Sigh. You can't enqueue on wp_head. Rather, you have to do it on an init action, such as: add_action ( 'init', 'lbIncludes'); But I still can't get the css to appear. Commented Apr 22, 2010 at 9:04
  • Could it be the }; in the last line? It should be } Commented Mar 15, 2013 at 16:09

2 Answers 2

2

If you want to load jQuery before your scripts do this:

wp_register_script('myScript', WP_PLUGIN_URL . '/myScript/myScript.bundle.js', array('jquery') );
Sign up to request clarification or add additional context in comments.

Comments

1

Try hooking to wp_print_styles and wp_print_scripts. To ensure jQuery is loaded first add the $deps parameter when you wp_enqueue_script.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.