Using jQuery

HI there,

I am building Twitter Bootstrap into my wordpress theme. I have managed to do that, and to include the jquery plugins. However I do not know where to put the "methods" in my theme.

See for example this page in the docs: http://twitter.github.com/bootstrap/javascript.html

Under Modals and then Methods (in fact for each plugin it has Methods) it gives different options that you can set. But I don't know where to put these snippets in my theme :slight_frown:

Any help would be greatly appreciated.

Best wishes,
AB

  • Mason
    • DEV MAN’s Sidekick

    Hiya Propaganda,

    To use any custom javascript you need to call the source in your theme's files such as in the theme's function.php file. Something like so:

    if( !is_admin()){
       wp_deregister_script('jquery');
       wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"), false, '1.3.2');
       wp_enqueue_script('jquery');
    }

    From there, you should add the appropriate selectors to your theme's markup as described on the page you linked to. Hope that helps!

    Thanks!

  • Abaloo
    • The Incredible Code Injector

    Thanks,

    I use that already in my functions.php.

    I was just looking for how to add additional plugins, where that would go. I've created separate file for my jQuery plugins and linked to that in the footer, and that's working great.

    Best wishes,

    AB

  • Abaloo
    • The Incredible Code Injector

    Hi again.

    No I've done all of that. I just wanted to be able to write "inline" (for want of a better word) jquery in some places, where it could still be accessed on all pages, but without altering the plugin scripts.

    AB

  • Mason
    • DEV MAN’s Sidekick

    Hiya AB,

    Ok, if you want to have a specific jquery action take place on all pages you could write that "inline" in the theme header right? That would get it done as it's loaded everytime.

    Thanks. If I still don't have it right for ya I'll ask for another set of eyes here that may be able to help :slight_smile:

  • Abaloo
    • The Incredible Code Injector

    Thanks for staying in touch with this.

    That's pretty much what I did (except I injected the additional actions through a separate file into the footer (as I believe the footer is generally best practice for jQuery/Javascript, except where specifically required in the header.

    Thanks again,
    AB

  • Mason
    • DEV MAN’s Sidekick

    Hiya AB,

    You're right - putting it in the footer is the preferred method as it allows for more of the page to load more quickly. I only recommended the header because there are sometimes where it is required and didn't want that to be a blocker for seeing this working for ya.

    Glad to hear it's sorted now though :slight_smile:

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.