Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question
    
Please learn more about WordPress before trying to make a commercial theme. –  Wyck Mar 2 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. –  audaz802 Mar 2 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 at 16:03

2 Answers 2

up vote 1 down vote accepted

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.

share|improve this answer
    
Thanks toscho, since there is no redundancy, I think this is the best thing to do. –  audaz802 Mar 2 at 5:47

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()
share|improve this answer
    
Thank you Brad. By now it is not the case since I'm not using a child theme but your code will be useful. –  audaz802 Mar 2 at 5:43
    
I've included what needs to be changed for parent themes. –  Brad Dalton Mar 2 at 9:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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