JQuery not working in wordpress

I have this jQuery script bit that can be found here: http://jsfiddle.net/RUqNN/45/

When I include this script in my Wordpress template, I am not working.

I checked the jquery source link, rewritten the code, nothing works.

<html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> </head> <body> <script type="text/javascript"> $(document).ready(function() { $(".move").toggle( function() { $("#teetimetag").animate({ right: "0px" }, "normal"); },function() { $("#teetimetag").animate({ right: "-200px" }, "normal"); }); }); </script> <div id="teetimetag"> <img class="move" src="http://test.tooheavytoskydive.com/wp-content/themes/newtheme/images/flag.png" style="float: left;" /> <div style="margin: 15px 0 0 50px;"> <a href="http://test.tooheavytoskydive.com/reservations/" style="color: #FFF; font-weight: bold; font-size: 17px;">Reserve your Tee-Time</a> </div> </div> </body> </html> 
0
source share
3 answers

The following javascript error is shown on your site: '$ is not a function'. It seems that jQuery is conflicting with another library. This can be solved by calling jQuery.noConflict () and replacing all $ with "jQuery". The code will look like this:

 jQuery.noConflict(); jQuery(document).ready(function() { jQuery(".move").toggle( function() { jQuery("#teetimetag").animate({ right: "0px" }, "normal"); },function() { jQuery("#teetimetag").animate({ right: "-200px" }, "normal"); }); }); 
+1
source

you need to register js files in the functions.php file of your template:

 wp_register_script('jquery', 'http://code.jquery.com/jquery-1.7.2.min.js'); 

http://codex.wordpress.org/Function_Reference/wp_register_script

0
source

Generally, you should not use the $ variable for jQuery unless you have used one of the shortcuts.The following is an example of how the jQuery shortcut is safe to use the $ variable:

 jQuery(function ($) { /* You can safely use $ in this code block to reference jQuery */ }); 

To load jquery into wordpress, use one of the following two versions. Include the code in the Plugin Page OR in function.php

 function include_jQuery() { if (!is_admin()) { wp_enqueue_script('jquery'); } } add_action('init', 'include_jQuery'); 

You can definitely use any meaningful function name instead of include_jQuery .

Alternatively, you can use the following code:

 function include_jQuery() { if (!is_admin()) { // comment out the next two lines to load the local copy of jQuery wp_deregister_script('jquery'); wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js', false, '1.8.3'); wp_enqueue_script('jquery'); } } add_action('init', 'include_jQuery'); 

You may like THIS link where I personally learn the above method (s). A Very BIG Thanks Ericm Martin!

-1
source

Source: https://habr.com/ru/post/979566/


All Articles