332 posts
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • Has been a member for 3-4 years
  • Bought between 10 and 49 items
  • Exclusive Author
  • United States
CadenGrant says

So my new theme was soft rejected because I usually deregister the default WP jquery script and link to the one hosted on Google but apparently now this is no longer allowed.

I’m having troubles getting the default WP jQuery to work. Here’s the code I usually use:

    wp_deregister_script( 'jquery' );
    wp_register_script( 'jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js' );
    wp_enqueue_script( 'jquery' );

Then I tried just this (which didn’t work):

    wp_enqueue_script( 'jquery' );

Then I tried putting <?php wp_enqueue_script( ‘jquery’ ); ?> right before wp_head(); in the header file, and when I did that the jQuery file was called but only after all the other scripts (after wp_head) somehow. Does anybody know how I can get this to work to use the default WP jQuery?

201 posts
  • Beta Tester
  • Sold between 50 000 and 100 000 dollars
  • Exclusive Author
  • Referred between 100 and 199 users
  • Bought between 10 and 49 items
  • Has been a member for 3-4 years
biyanpasau says

Try to enqueue all script

332 posts
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • Has been a member for 3-4 years
  • Bought between 10 and 49 items
  • Exclusive Author
  • United States
CadenGrant says

Edit: Nvm I got it :)

no-thumbnail
WordPress_Coding_Standards Recent Posts
Threads Started
7 posts
  • Has been a member for 1-2 years
WordPress_Coding_Standards says

This is so great that Themeforest is finally enforcing this. Thank you Envato!!!!

The theme authors need to read up on the codex. You don’t enqueue scripts in the header. You enqueue them via a call back function that you attach to the wp_enqueue_scripts hook.


function my_prefix_load_js() {
     wp_enqueue_script( 'pretty-photo', get_template_dir().'/js/pretty-photo.min.js', array( 'jquery' ), false);
}

add_action( 'wp_enqueue_scripts', 'my_prefix_load_js' )

This is how dependencies work and why so many themes on here break when plugins use proper dependencies. the array( ‘jquery’ ) tells WordPress that your script relies on jquery to work so it will then make sure jquery is loaded before your script. You don’t need to enqueue it because you defined it as a dependency.

In the past when you put all your registers script calls in header.php its too late and will cause two versions of jquery to get loaded which why so many plugins break.

AGain kudos to Envato for stepping up and enforcing The WordPress APIs!

by
by
by
by
by
by