Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

William Whitworth
William Whitworth
6,117 Points

Just want to confirm if this looks right.

Hey all, I just added this to my Wordpress function.php file and it seems to be working, I just wanted to double check if this was the right method of calling jquery and its plugins.

    <?php 
    if (!is_admin()) add_action("wp_enqueue_scripts", "my_jquery_enqueue", 11);
    function my_jquery_enqueue() {
       wp_deregister_script('jquery');
       wp_register_script('jquery', "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") .     "://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js", false, null);
       wp_enqueue_script('jquery');

       wp_register_script('modernizr', get_template_directory_uri() . '/js/vendor/modernizr-2.6.2-respond-     1.1.0.min.js', array('jquery'), '', false );
        wp_enqueue_script('modernizr');

       wp_register_script('columnizer', get_template_directory_uri() . '/js/columnizers.js', array('jquery'), '', false      );
       wp_enqueue_script('columnizer');

       wp_register_script('bxslider', get_template_directory_uri() . '/js/jquery.bxslider.min.js', array('jquery'), '', true );
       if(is_page('home')) {
           wp_enqueue_script('bxslider');
       }

       wp_register_script('bootstrap', get_template_directory_uri() . '/js/vendor/bootstrap.min.js', array('jquery'), '', true );
       wp_enqueue_script('bootstrap');

       wp_register_script('plugins', get_template_directory_uri() . '/js/plugins.js', array('jquery'), '', true );
       wp_enqueue_script('plugins');

       wp_register_script('stickem', get_template_directory_uri() . '/js/jquery.stickem.js', array('jquery'), '', true );
       wp_enqueue_script('stickem');

       wp_enqueue_script('imageloader', get_template_directory_uri() . '/js/imagesloaded.pkgd.min.js',     array('jquery'), '', true );
       wp_enqueue_script('imageloader');
    }
    ?>

2 Answers

Andrew Chalkley
STAFF
Andrew Chalkley
Treehouse Guest Teacher

If it's working it may be fine :)

Pinging Zac Gordon for sanity check.

Zac Gordon
STAFF
Zac Gordon
Treehouse Guest Teacher

First, you don't have to worry about calling jQuery. If you say a JS file is dependent on jQuery it will load it automatically.

Second, you don't have to use the wp_enqueue_script twice. It is used in conjunction with wp_register_script. Check out this video: http://teamtreehouse.com/library/how-to-build-a-wordpress-theme/preparing-to-code-wordpress-templates/linking-javascript-2