I need to add jQuery library to WordPress page. The page is rendered by a plugin shortcode.
I've used the below methods but I don't see it working for my jQuery script.
I tried to add these below script in main plugin file where the plugin name and version go.
DESN'T WORK:
function my_init() {
if (!is_admin()) {
wp_enqueue_script('jquery');
}
}
add_action('init', 'my_init');
DESN'T WORK
function my_init() {
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.4.2/jquery.min.js', false, '1.4.2');
wp_enqueue_script('jquery');
}
}
add_action('init', 'my_init');
I actually need to add below library to my WordPress front end page?
http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js
but if i use it directly like below then it works.
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
Second, How can see it loaded in my browser loaded along with other code?
wp_head()
wp_enqueue_scripts
, notinit
. Your first example should work fine then, assuming, as @veganista pointed out, that your theme callswp_head()