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:
I wrote this answer a while ago. I should clarify that the best place to enqueue your scripts and styles is within the wp_enqueue_scripts hook. So for example:
The wp_enqueue_scripts action will set things up for the “frontend”. You can use the admin_enqueue_scripts action for the backend (anywhere within wp-admin) and the login_enqueue_scripts action for the login page.
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'));
Update Sept. 2017
I wrote this answer a while ago. I should clarify that the best place to enqueue your scripts and styles is within the
wp_enqueue_scripts
hook. So for example:The
wp_enqueue_scripts
action will set things up for the “frontend”. You can use theadmin_enqueue_scripts
action for the backend (anywhere within wp-admin) and thelogin_enqueue_scripts
action for the login page.Put it in the
init()
function for your plugin.It took me also some time before I found the (for me) best solution which is foolproof imho.
Cheers
To include CSS and jQuery in your plugin is easy, try this:
I found this great snipped from this site How to include jQuery and CSS in WordPress â The WordPress Way
Hope that helps.
Accepted answer is incomplete. You should use the right hook:
wp_enqueue_scripts
Example:
Just to append to @pixeline’s answer (tried to add a simple comment but the site said I needed 50 reputation).
If you are writing your plugin for the admin section then you should use:
The admin_enqueueu_scripts is the correct hook for the admin section, use wp_enqueue_scripts for the front end.
See http://codex.wordpress.org/Function_Reference/wp_enqueue_script
Example
First you need to register the style and css using wp_register_script() and wp_register_style() functions
After this you can call the wp_enqueue_script() and wp_enqueue_style() functions for loading the js and css in required page
I fount a nice example here http://wiki.workassis.com/wordpress-create-advanced-custom-plugin-using-oop/
Very Simple:
Adding JS/CSS in the Front End:
Adding JS/CSS in WP Admin Area: