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 ($) { });
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!
source share