WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] wp_head + wp_enqueue_script - problem loading the script into head section (3 posts)

  1. Michael Fields
    Themer
    Posted 6 years ago #

    Hello. I'm at my wits end with this - maybe someone can help. I would like to use jQuery on my blog, but I cannot seem to get to enqueue using wp_enqueue_script(). This code is in a custom activated plugin:

    add_action('wp_head', 'mfDevLoadScripts');
    function mfDevLoadScripts() {
    	wp_enqueue_script('jquery');
    }

    Nothing happens! But... If I try:

    'add_action('wp_head', 'mfDevLoadScripts');
    function mfDevLoadScripts() {
    print 'flying monkeys';
    }`

    I get "flying monkeys" printed across the top of my screen. Please help if you can!
    Thanks!

  2. Michael Fields
    Themer
    Posted 6 years ago #

    OK.... Answered my own question here. This is how you do it do it:

    add_action('init', 'mfDevLoadScripts');
    function mfDevLoadScripts() {
    	wp_enqueue_script('jquery');
    }
  3. Mark Barnes
    Member
    Posted 5 years ago #

    For others who may read the thread, and need (like me) to use the wp_head hook rather than init, you can also use
    add_action('wp_head', 'mfDevLoadScripts', 0);
    to ensure the function loads early enough.

Topic Closed

This topic has been closed to new replies.

About this Topic