1

I understood that WordPress ALWAYS enqueues jQuery on all themes, thus it's reduntant to enqueue another jQuery with the same version.

However, while developing a theme, for testing purposes I moved it to a subdomain (same domain, another WP installation, no content but the "Hello World" post).

While the first enqueued normally the jQuery, the second stopped some functionalities and looking inside I've found that WordPress was not including jQuery automatically anymore.

The question is: Does WordPress wait for something (don't know, maybe a minimum of widgets on widget areas, menus, etc) to call the script? To make sure, do I have to enqueue the native jQuery manually? I'm developing a theme with the purpose to sell it on Theme Forest and they only allow the native WP jQuery (no way to dequeue it and add from another resource).

I'm using Wordpress 3.8

  • Please learn more about WordPress before trying to make a commercial theme. – Wyck Mar 2 '14 at 4:22
  • Honestly I think that starting a project is the best way to learn something new and trying to make a commercial theme increases the responsibility to learn it well and on the right way. Also, your comment didn't aggregated any value to this question and sounded rude for me. If you can't help try at less to be gentle. – Rico Letterman Mar 2 '14 at 5:41
  • I agree, but it should not be commercial, would you built a house for someone with no experience? The question is very basic and it might be a better idea not just for your clients but your sanity to make a bunch of non-commercial themes first, or one for wordpress.org which has to pass a review team. – Wyck Mar 2 '14 at 16:03
2

On the frontend, WordPress enqueues jQuery only when the admin bar is visible, usually only for users who are logged in.

If you need jQuery, enqueue it. It will not be included twice in this case.

  • Thanks toscho, since there is no redundancy, I think this is the best thing to do. – Rico Letterman Mar 2 '14 at 5:47
0

Do WordPress wait for something (don't know, maybe a minimum of widgets on widget areas, menus, etc) to call the script?

No. WordPress will load the script if you tell it to using the correct method.

You would use this method for loading scripts via your child themes functions file.

function my_scripts_method() {

wp_enqueue_script('custom-script',

get_bloginfo( 'stylesheet_directory' ) . '/js/custom_script.js', array( 'jquery' ));
}

add_action( 'wp_enqueue_scripts', 'my_scripts_method' )

Assumes your script is located in a folder named js in your child themes root directory.

For parent themes, replace:

get_bloginfo( 'stylesheet_directory' )

With:

get_template_directory_uri()
  • Thank you Brad. By now it is not the case since I'm not using a child theme but your code will be useful. – Rico Letterman Mar 2 '14 at 5:43
  • I've included what needs to be changed for parent themes. – Brad Dalton Mar 2 '14 at 9:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.