I have this code

function this_is_my_shortcode(){
    wp_register_script('per-pas-belanja-online', plugins_url('js/per-pas-belanja-online.js', __FILE__), array('jquery'), '1.0.0');
    wp_enqueue_script('per-pas-belanja-online');
    return '<div id="poppedout">Blah</div>';
}
add_shortcode('bubba', 'this_is_my_shortcode');

The div is appear on the page, but the script is not. What mistake i have done ?

3 Answers
3

Straight from the Codex

Use the wp_enqueue_scripts action to call this function, or admin_enqueue_scripts to call it on the admin side. Calling it outside of an action can lead to troubles.

Leave a Reply

Your email address will not be published. Required fields are marked *