WordPress.org

Ready to get started?Download WordPress

Forums

add_action to enqueue_script is not working (2 posts)

  1. matrym
    Member
    Posted 4 years ago #

    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?

    Thanks in advance for your help

  2. ipurush
    Member
    Posted 4 years ago #

    add_action ( 'wp_head', 'lbIncludes');

    This does not work as the wp_head is called after the javascript is supposed to be registered.

    You need to use add_action ( 'init', 'lbIncludes'); instead

Topic Closed

This topic has been closed to new replies.

About this Topic