WordPress.org

Ready to get started?Download WordPress

Forums

How to get Jquery to work in wordpress (7 posts)

  1. timlcooley
    Member
    Posted 1 year ago #

    I am trying to learn how to build my own slider and I can not figure out how to get jquery to be recognized in wordpress. I am copying and pasting working functions and nothing is working. Any help would be great. I would prefer a step by step guide I just can't find one.

  2. You need to correctly load javascript in a theme; see http://codex.wordpress.org/Function_Reference/wp_enqueue_script

    Use Firebug with Firefox, or use the developer tools in Chrome or Safari or IE to see what javascript is loading on your site and how to work with it.

  3. Keith Burgie
    Member
    Posted 1 year ago #

    Using jQuery in WordPress isn't any different from using it elsewhere.

    Step one would be to put this line in the <head> section of header.php:
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

    With that in place the code that you are copying and pasting should work.

  4. WebTechGlobal
    Member
    Posted 1 year ago #

    Keith Burgie sorry but your comment is incorrect in most cases.

    When providing support on here we must always assume that someone is developing a plugin or theme to be shared and that requires wp_enqueue_script to be used to avoid conflicts.

    If your developing a theme or plugin which is not to be shared, then yes you can use the approach in your example however each time a new plugin is installed a conflict may happen.

    timelcooley I also recommend doing a check on $_GET['page'] and only calling wp_enqueu_script when the page is one of your plugin pages. This makes for a lighter WordPress and goes further to avoiding conflicts especially when your just grasping all of this.

    For example. My plugins page slugs all contain "csv2post_" and using strstr() I check if $_GET['page'] has csv2post_ within the string which might be "csv2post_page_projects". I load many script files and a lot of jQuery UI in this plugin, when the user open my plugins own admin pages.

    This is secondary important to what songdogtech has already said however. That is the part you need to learn and get right first.

  5. @Keith Burgie: You're absolutely wrong. Read the links I posted.

  6. Keith Burgie
    Member
    Posted 1 year ago #

    @songdogtech: Feel free to delete my comments if you're able. In my experience what I suggested has worked. I haven't built a plugin and didn't consider that his project might be something to share.

  7. @Keith Burgie: @timlcooley is including jQuery in a theme; your method will break plugins the theme/site tries to use.

Topic Closed

This topic has been closed to new replies.

About this Topic