WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] wp_enqueue_script issues (16 posts)

  1. iAyo
    Member
    Posted 1 year ago #

    hi, the scripts i enqueued in functions.php for my theme using wp_enqueue_script() arent displaying in source code, when site is loaded, indicating that the scripts aren't being loaded in wp_head().
    i check to see if they are queued with
    wp_script_is('queue')
    it returns true for all of them however
    wp_script_is('to_do') and wp_script_is('done') return false
    here is my code:

    function goldrush_js_enqueue(){
    
    wp_deregister_script( 'jquery' );
    wp_enqueue_script( 'jquery' );//wordpress provided jQuery library
    wp_enqueue_script( 'jquery.tweet', get_template_directory_uri() . '/js/jquery.tweet.js', array('jquery'));
    wp_enqueue_script( 'flexislider',get_template_directory_uri() . '/js/jquery.flexslider-min.js', array('jquery'));
    wp_enqueue_script( 'menujs',get_template_directory_uri() . '/js/menu.js', array('jquery'));
    wp_enqueue_script( 'flicker',get_template_directory_uri() . '/js/jflickrfeed.min.js', array('jquery'));
    wp_enqueue_script( 'quicksand',	get_template_directory_uri() . '/js/custom.quicksand.js', array('jquery'));
    wp_enqueue_script( 'prettyphoto',get_template_directory_uri() . '/js/jquery.prettyPhoto.js', array('jquery'));
    }
    add_action('wp_enqueue_scripts', 'goldrush_js_enqueue');

    please help, its urgent, thanks

  2. s_ha_dum
    Member
    Posted 1 year ago #

    URL?

    Why do you deregister 'jquery' only to register it again?

  3. Max
    Member
    Posted 1 year ago #

    If you deregister is, you cannot simply run:

    wp_enqueue_script( 'jquery' );

    afterward, as the process of de-registering it actually removes WordPress' reference to it, and it will not know where to find it, so nothing that depends on it will get enqueued.

    You should remove both the following lines:

    wp_deregister_script( 'jquery' );
    wp_enqueue_script( 'jquery' );

    in your function, since you have jQuery listed as a dependency in every-other call... it will be added automatically.

  4. s_ha_dum
    Member
    Posted 1 year ago #

    Oops, good catch, Max. He doesn't re-register it. He just tries to re-enqueue it.

  5. iAyo
    Member
    Posted 1 year ago #

    Hi, Max removed both lines but still no joy.
    However,
    wp_script_is( $handle, $list = 'queue')
    returns true when tested on all the script handles except when the handle is 'jquery' where it returns false meaning jQuery library doesn't get enqueued.

    Also this function returns false on all $handle when $list = 'to_do'.

    please help...

  6. iAyo
    Member
    Posted 1 year ago #

    I wanted to note that when i put
    wp_enqueue_script( 'jquery' );
    at the top of my functions.php file outside the
    function goldrush_js_enqueue(){}
    wp_script_is( 'jquery', $list = 'queue' )
    returns true cant understand why....

  7. s_ha_dum
    Member
    Posted 1 year ago #

    That strikes me as somewhat odd behavior. Is there a plugin, or perhaps some other component of your theme, that might be messing with jQuery registration? Can you post an URL?

  8. iAyo
    Member
    Posted 1 year ago #

    its still on my production machine its not live yet but i will install afresh copy of wordpress and try it out

  9. iAyo
    Member
    Posted 1 year ago #

    i just put the theme on a fresh install of wordpress and still cant get the scripts to run. Here is the URL:

    http://www.goldrushbeauty.com/

  10. Max
    Member
    Posted 1 year ago #

    jQuery is still not being loaded... can you past your functions.php to pastebin so we can look at it...

    Also your header.php as I notice there is some inline script that is being output before the scripts that are being enqueued by WordPress.

  11. iAyo
    Member
    Posted 1 year ago #

    <script src="http://pastebin.com/embed_js.php?i=pZKrLxRV"></script>

  12. Max
    Member
    Posted 1 year ago #

    I think I will download that theme, as I notice that is including a setup file, @s_ha_dum is right when he says that is odd behaviour...

    I did notice one small issue:

    You are missing a jQuery dependency in

    wp_enqueue_script( 'jquery.tweet', get_template_directory_uri() . '/js/jquery.tweet.js');

    This is however not the cause of the other issue... Will post back in a min when I have looked at the theme...

  13. iAyo
    Member
    Posted 1 year ago #

    functions.php posted in pastebin

  14. What you've posted here will never work as a link (thank goodness too!) but this will.

    http://pastebin.com/pZKrLxRV

    Please see this link for instructions on how to use pastebin.com.

  15. iAyo
    Member
    Posted 1 year ago #

    Thank you Jan,

    I failed to mention that im using wordpress v3.3.2, i hope this will help in solving the issue.

  16. iAyo
    Member
    Posted 1 year ago #

    Hi,
    figured out what was wrong, the scripts and styles were added below the output of functions i attached to the wp_script_styles() hook. I now need to figure out why the $priority isn't making them print immediately after wp_head().

    I thank you all for your help.....

Topic Closed

This topic has been closed to new replies.

About this Topic