Ajay Patel
Ajay Patel

Reputation: 5418

How to include jQuery plugin with Wordpress?

In my plugin i need to include 1 css and 2 js file (jquery.min.js and jquery.googleplus-activity-1.0.min.js).

i am using this code

function my_init_method() 
{
    wp_deregister_script( 'jquery' );
    wp_enqueue_script( 'jquery', '' . get_bloginfo('wpurl') . '/wp-content/plugins/googe_plus/js/jquery.min.js');
}

function addHeaderCode() {
    echo '<link type="text/css" rel="stylesheet" href="' . get_bloginfo('wpurl') . '/wp-content/plugins/googe_plus/css/style.css" />' . "\n";

}


function my_jsscripts_method() {

    wp_deregister_script( 'jquery' );
    wp_register_script( 'jquery', '' . get_bloginfo('wpurl') . '/wp-content/plugins/googe_plus/js/jquery.googleplus-activity-1.0.min.js');
    wp_enqueue_script( 'jquery' );
}
add_action('init', 'my_init_method');
//Include CSS
add_action('wp_head', 'addHeaderCode');

//Include JS
add_action('wp_enqueue_scripts', 'my_jsscripts_method');

but not able to add both of js file. Keep in mind that i have to include jquery.min.js first then css and another js file jquery.googleplus-activity-1.0.min.js

Upvotes: 1

Views: 854

Answers (1)

Hobo
Hobo

Reputation: 7611

I'd use a different handle for the jquery.googleplus-activity-1.0.min.js file. You may be confusing WordPress trying to reuse "jquery". So something like:

function my_jsscripts_method() {
    wp_register_script( 'jquery.googleplus', '' . get_bloginfo('wpurl') . '/wp-content/plugins/googe_plus/js/jquery.googleplus-activity-1.0.min.js');
    wp_enqueue_script( 'jquery.googleplus' );
}

Might be worth using the third argument to wp_register_script to have it depend on jquery.

As an aside, unless you have a very good reason, I'd probably use the version of jQuery that comes with WordPress (rather than replacing it). You may get compatibility issues.

Upvotes: 2

Related Questions