Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am just trying to create a plugin that will add some JS to the header and custom CSs. I have this below but it adds the css wrong and shows as JS. This is first plugin i have attempted.

<?php
/**
 * Plugin Name: mmoore5553 Simple Range Slider
 * Plugin URI: mailto:mmoore5553@gmail.com
 * Description: Simple Range Slider
 * Version:  1.0
 * Author: mmoore5553@gmail.com
 * Author URI: 
 * License:GPL2
 */


function SimpleRangeSlider() {
wp_register_script('SimpleRangeSlider', plugins_url('/js/simple-slider.js', __FILE__), array('jquery'),'1.1', true);
wp_enqueue_script('SimpleRangeSlider');
}

add_action( 'wp_enqueue_scripts', 'SimpleRangeSlider' ); 



function SimpleRangeSlider1() {
wp_register_script('stylesheet1', plugins_url('/css/simple-slider.css', __FILE__));
wp_enqueue_script('stylesheet1');
}

add_action( 'wp_enqueue_scripts', 'SimpleRangeSlider1' );  

function SimpleRangeSlider2() {
wp_register_script('stylesheet2', plugins_url('/css/simple-slider-volume.css', __FILE__));
wp_enqueue_script('stylesheet2');
}

add_action( 'wp_enqueue_scripts', 'SimpleRangeSlider2' );  
?>
share|improve this question
add comment

2 Answers 2

up vote 3 down vote accepted

wp_enqueue_script is for… scripts. You want wp_enqueue_style (and wp_register_style) for stylesheets.

Also note that you can enqueue as many things as you'd like in a single function, no need to create a separate function for each. You can also pass all the same arguments to enqueue as you do to register, no need to register them first if you're just enqueueing in one place.

share|improve this answer
    
Thank you. I finally got it working. I did not know you could put it all in one. Thank you on the correct syntax. I knew it was something simple I was missing. –  matthew moore Mar 12 at 15:01
add comment

As Milo already told you, you need to use wp_enqueue_script for scripts and use wp_enqueue_style for Stylesheet files.

http://codex.wordpress.org/Function_Reference/wp_enqueue_script

https://codex.wordpress.org/Function_Reference/wp_enqueue_style

Read these pages, they will give all the info you need.

Also, you can actually enqueue multiple scripts / styles in single function, no need to create function for each style file or script file enqueue.

share|improve this answer
    
Answers should be more than plain links. They should actually be an answer instead of a route where someone will maybe find an answer. Please help preventing link rot, edit your answer and provide the needed information that helps the OP as well as later visitors to solve their problem. –  kaiser Mar 14 at 7:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.