How To Include CSS and jQuery in my WordPress plugin ?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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_scriptshook. So for example:The
wp_enqueue_scriptsaction will set things up for the “frontend”. You can use theadmin_enqueue_scriptsaction for the backend (anywhere within wp-admin) and thelogin_enqueue_scriptsaction for the login page.