1

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

2
  • not to answer your question, but please be reminded that other plugins may use jQuery also. Check whether jQuery exists before adding the JS. Commented Jan 9, 2012 at 9:01
  • @ShivanRaptor yes i know but i think globally that may use not using it also, so i have to include it Commented Jan 9, 2012 at 9:03

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.