Back
How To Include CSS and jQuery in my WordPress plugin?
The best place to include CSS and jQuery in my WordPress plugin in your scripts and styles is within the wp_enqueue_scripts hook. Below is an example in which you can see these:-
add_action('wp_enqueue_scripts', 'callback_for_setting_up_scripts');function callback_for_setting_up_scripts() { wp_register_style( 'namespace', 'http://locationofcss.com/mycss.css' );wp_enqueue_style( 'namespace' );wp_enqueue_script( 'namespace for script', 'http://locationofscript.com/myscript.js', array( 'jquery' ) ); }
add_action('wp_enqueue_scripts', 'callback_for_setting_up_scripts');
function callback_for_setting_up_scripts() {
wp_register_style( 'namespace', 'http://locationofcss.com/mycss.css' );
wp_enqueue_style( 'namespace' );
wp_enqueue_script( 'namespace for script', 'http://locationofscript.com/myscript.js', array( 'jquery' ) ); }
What wp_enqueue_scripts action does is it set up the things for the "frontend". Whereas you can use the admin_enqueue_scripts action for the backend and the login_enqueue_scripts action for the login page.
31k questions
32.8k answers
501 comments
693 users