post-page

Adding Scripts Properly to WordPress Part 1 – wp_enqueue_script

16
responses
by
 
on
May 6th, 2010
in
HOW-TO, WordPress FAQs
heading
heading
heading
16
Responses

 

Comments

  1. quicoto (39 comments.) says:

    Interesing. I was not using this function I was just adding the scripts in the normal way.

    Regards

  2. Andrew@BloggingGuide (90 comments.) says:

    Like Quicoto, I am also just adding scripts the usual way that I know of, so this is really something new to me and much more helpful. Thanks for sharing this. Will be bookmarking this.

  3. Milan (5 comments.) says:

    Why don’t you use WP_PLUGINS_URL instead of WP_CONTENT_URL . ‘plugins ?

  4. Otto (215 comments.) says:

    Use of those WP_*_URL constants is actually not recommended. Instead, you should use the functions designed for this purpose.

    Will produce: http://example.com/blog/wp-content/whatever

    There’s also plugins_url(), includes_url(), admin_url(), and site_url(). These have been around since WP 2.6.

    WP 3.0 adds a bunch of new ones, like home_url and network_home_url and so forth. All these work basically the same way.

    The reason you should use these is that they take path changes and https and other things into account and such. They’re also shorter and less likely to break in the future than defines and such are.

  5. Byron (11 comments.) says:

    Thanks for publishing this article! It mirrors one that I published a while back on my whypad blog, but this will definitely hit a bigger audience. This script inclusion problem is the single biggest problem I see with people who use my plugin. Most of my forum posts are people saying that uploading images doesn’t work, and 95% of the time it is due to either the theme or some other plugin loading jQuery without using the enqueue function. I’ve seen jQuery being loaded 3 or 4 times on the same page while helping folks.

    So, THANK YOU, THANK YOU, THANK YOU!!!!

    • Ronald huereca (32 comments.) says:

      @Byron,

      Wow, never seen it that bad.

      Another “sin” I didn’t mention is people who still use the “onload” event.

      • Byron (11 comments.) says:

        @Ronald,

        You might also mention the wp_head() and wp_footer() sins of omission as well. Those seem to be getting better, but I still get a fair number of people coming by with a missing wp_footer, which is where Thickbox gets added.

        Thanks again, and cheers!
        Byron

  6. John says:

    Hi Ronald,

    You mentioned this:

    “Another “sin” I didn’t mention is people who still use the “onload” event.”

    Can you enlighten me on why this a sin when adding a script to WP?

  7. Ian.J.Gough (1 comments.) says:

    After searching for nearly 30 mins to get the syntax so i could understand what the true and false were being used for this article is the clearest and easiest to understand. Many Thanks it’s helped me to load jquery and jquery-ui.min from google and place it in the footer.
    Great work thanks for sharing,
    Ian

  8. Sam (1 comments.) says:

    Awesome article, I love it!!!
    I had so many problems with my plugin, because of jquery, now it’s all solved :)



Obviously Powered by WordPress. © 2003-2013

page counter
css.php