How To Include CSS and jQuery in my wordpress plugin ?
+1
A:
See http://codex.wordpress.org/Function_Reference/wp_enqueue_script
Example
<?php
function my_init_method() {
wp_deregister_script( 'jquery' );
wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js');
}
add_action('init', 'my_init_method');
?>
powtac
2010-09-21 12:28:16
How To Include CSS files ?
faressoft
2010-09-21 12:30:20
@faressoft - see accepted answer
Steven
2010-10-26 08:47:13
A:
For styles
wp_register_style( 'namespace', 'http://locationofcss.com/mycss.css' );
Then use:
wp_enqueue_style('namespace');
wherever you want the css to load.
Scripts are as above but the quicker way for loading jquery is just to use enqueue loaded in an init for the page you want it to load on:
wp_enqueue_script('jquery');
Unless of course you want to use the google repository for jquery.
You can also conditionally load the jquery library that your script is dependent on:
wp_enqueue_script('namespaceformyscript', 'http://locationofscript.com/myscript.js', array('jquery'));
Darren
2010-09-21 13:26:33