Jquery Script in Wordpress

Discussion in 'JavaScript' started by d0cpaul, Jun 19, 2013.

  1. #1
    I'm trying to implement this jquery script into a Wordpress page but having trouble making it work.. Does anyone know how I can make this work in a Wordpress page?

    http://jsfiddle.net/SO_AMK/a9dnW/3/

    Thanks!
     
    d0cpaul, Jun 19, 2013 IP
  2. ActiveFrost

    ActiveFrost Notable Member

    Messages:
    2,072
    Likes Received:
    63
    Best Answers:
    3
    Trophy Points:
    245
    #2
    The same way you would make it work on a non-Wordpress site.
    1. Download and install jQuery (too many tutorials already available for me not to explain it from the very beginning);
    2. Add that script block at the end of your page (before the closing body tag).
     
    ActiveFrost, Jun 19, 2013 IP
  3. vikaskumarbhardwaj

    vikaskumarbhardwaj Banned

    Messages:
    83
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    98
    Digital Goods:
    1
    #3
    Hi,
    Wordpress inbuilt jquery does'nt understands $ sign. You should use jQuery instead.
    For example
    $("#test p").delay(1000).animate({"opacity": "1"}, 700);
    Code (markup):
    change to
    jQuery("#test p").delay(1000).animate({"opacity": "1"}, 700);
    Code (markup):
    or you can pass $ in ready function and use your previous code without any problem.
    jQuery(document).ready(function ($) {
        $("#test p").delay(1000).animate({"opacity": "1"}, 700);
    }
    Code (markup):
     
    vikaskumarbhardwaj, Jun 21, 2013 IP
  4. d0cpaul

    d0cpaul Member

    Messages:
    119
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #4
    Sounds good thanks for the information. So If I'm trying to add this to a page how would I do that?

    Would I add the script to the page like this? I'm doing something wrong because it isn't working.
    <script> jQuery(document).ready(function ($) {
        $("#test p").delay(1000).animate({"opacity": "1"}, 700);
    }</script>
    Code (markup):
     
    d0cpaul, Jun 22, 2013 IP
  5. sarahk

    sarahk iTamer Staff

    Messages:
    28,826
    Likes Received:
    4,541
    Best Answers:
    123
    Trophy Points:
    665
    #5
    You still have a $ in there
    <script> jQuery(document).ready(function ($) {
    jQuery("#test p").delay(1000).animate({"opacity": "1"}, 700);
    }</script>
    Code (markup):
    Oh, and never link to your own copy of jQuery, use the one that wordpress has.
     
    sarahk, Jun 23, 2013 IP
    ryan_uk and Devtard like this.
  6. d0cpaul

    d0cpaul Member

    Messages:
    119
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #6
    Thanks for the help I'm completely new to Jquery/Javascript. I can't seem to get this working still... Can someone check out the page I'm working on and direct me how to get the script working?

    I appreciate it! :D
     
    d0cpaul, Jun 23, 2013 IP
  7. sarahk

    sarahk iTamer Staff

    Messages:
    28,826
    Likes Received:
    4,541
    Best Answers:
    123
    Trophy Points:
    665
    #7
    sarahk, Jun 23, 2013 IP
  8. d0cpaul

    d0cpaul Member

    Messages:
    119
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #8
    I'm aware of that but I just can't get it to work, maybe it's not compatible with Wordpress's default jquery or something?

    I'm running the latest version of Wordpress with the Inovado theme.
    Here is the page I am trying to develop maybe someone could see what I'm doing wrong:
    http://trailviewer.com/dev/register
     
    d0cpaul, Jun 24, 2013 IP
  9. sarahk

    sarahk iTamer Staff

    Messages:
    28,826
    Likes Received:
    4,541
    Best Answers:
    123
    Trophy Points:
    665
    #9
    I use chrome so I 'inspected' the page and got this

    [​IMG]

    Is fancybox a standard jquery plugin that you've chosen to use or did it come with the Inovado theme?

    I suspect (but don't know for sure) that wordpress needs a different version of the plugins because of the jQuery versus $ thing.

    If it came with the theme then go back to the theme creator and ask why the plugin might be throwing errors.

    If you've chosen to use it then do a search for how to use jquery plugins with wordpress.
     
    sarahk, Jun 24, 2013 IP
  10. d0cpaul

    d0cpaul Member

    Messages:
    119
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #10
    I believe fancybox is built into the theme because I didn't install it and it's not in the plugin menu.
     
    d0cpaul, Jun 24, 2013 IP
  11. sarahk

    sarahk iTamer Staff

    Messages:
    28,826
    Likes Received:
    4,541
    Best Answers:
    123
    Trophy Points:
    665
    #11
    Inovado is from Themeforest so you should get excellent support from them.
     
    sarahk, Jun 24, 2013 IP
  12. vikaskumarbhardwaj

    vikaskumarbhardwaj Banned

    Messages:
    83
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    98
    Digital Goods:
    1
    #12
    I got That you have not defined jquery.
    This is way to do in wordpress.

    add_action('wp_enqueue_scripts','load_javascripts');
    function load_javascripts(){
        wp_enqueue_script('jquery');
    }
    PHP:
    This will add jquery in header of theme.
    Add this in functions.php
     
    vikaskumarbhardwaj, Jun 25, 2013 IP