Title: Enqueue style and scripts
Last modified: July 10, 2018

---

# Enqueue style and scripts

 *  Resolved [VM06](https://wordpress.org/support/users/vm06/)
 * (@vm06)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/enqueue-style-and-scripts/)
 * Hello,
 * I created a plugin on my website just to add JS and CSS (rather than a child 
   theme).
    So, on my PHP file, I wrote this code to add some style but this is 
   not working :
 *     ```
       function wpb_adding_styles() {
       	wp_register_style('css_perso', plugin_dir_url( __FILE__).'plugin_perso/plugin_perso_css/css_perso.css');
       	wp_enqueue_style('css_perso');
       }
       add_action('wp_enqueue_scripts','wpb_adding_styles');
       ```
   
 * Do you have any idea why this does not work?
    Thanks.

Viewing 8 replies - 1 through 8 (of 8 total)

 *  [Jacob Peattie](https://wordpress.org/support/users/jakept/)
 * (@jakept)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/enqueue-style-and-scripts/#post-10479353)
 * Can you see the `<link rel="stylesheet"`… tag added to the header of your site.
   If so, check the URL. Is it correct?
 *  Thread Starter [VM06](https://wordpress.org/support/users/vm06/)
 * (@vm06)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/enqueue-style-and-scripts/#post-10479409)
 * Thanks for your quick answer :).
    Yes I see it loaded : <link rel=’stylesheet’
   id=’css_perso-css’ href=’[http://wordpress-doc/wp-content/plugins/plugin_perso/plugin_perso_css/css_perso.css?ver=4.9.7&#8242](http://wordpress-doc/wp-content/plugins/plugin_perso/plugin_perso_css/css_perso.css?ver=4.9.7&#8242);
   type=’text/css’ media=’all’ />. The URL is correct but it is not the last which
   is loaded (there are 6 other stylesheets that are loaded after
 *  Thread Starter [VM06](https://wordpress.org/support/users/vm06/)
 * (@vm06)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/enqueue-style-and-scripts/#post-10479436)
 * Yes, I think this is the problem because I have just added “!important” on my
   stylesheet and this is OK.
    So how can I do to have this loaded lastly? Do I 
   have to add a dependency? And just another thing : I am used to create child 
   themes and add my functions code on my child theme functions.php. How do I do
   with a specific plugin to add my functions? Thanks.
 *  [Marcus Kober](https://wordpress.org/support/users/marcuskober/)
 * (@marcuskober)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/enqueue-style-and-scripts/#post-10479548)
 * Hi there,
 * find out the id of the last css file that should be loaded right before your 
   plugin css file. Let’s say the id of this file (if it is loaded by wp_enqueue_style
   too) is ‘my-css-file-id’.
 * Add this id as a dependency to wp_register_style:
 * `wp_register_style('css_perso', plugin_dir_url( __FILE__).'plugin_perso/plugin_perso_css/
   css_perso.css', array('my-css-file-id'));`
 * wp_register_style accepts an array with dependencies after the src.
 * When it comes to the functions.php: your plugin itself is the functions.php in
   this case! The php file of the plugin can be used similar to the functions.php–
   so to say.
 *  Thread Starter [VM06](https://wordpress.org/support/users/vm06/)
 * (@vm06)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/enqueue-style-and-scripts/#post-10479629)
 * Thanks for you answer. I tried this code replacing the id but this does not work.
   The file does not load now.
 *     ```
       function wpb_adding_styles() {
       	wp_register_style('css_perso', plugin_dir_url( __FILE__).'plugin_perso_css/css_perso.css', array('wiki-style-css'));
       	wp_enqueue_style('css_perso');
       }
       add_action('wp_enqueue_scripts','wpb_adding_styles');
       ```
   
 *  Thread Starter [VM06](https://wordpress.org/support/users/vm06/)
 * (@vm06)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/enqueue-style-and-scripts/#post-10479674)
 * It is OK, I have just added a higher priority on add_action and this works perfectly.
   
   Thanks.
 *  [Jacob Peattie](https://wordpress.org/support/users/jakept/)
 * (@jakept)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/enqueue-style-and-scripts/#post-10479701)
 * The actual handle of the stylesheet will exclude the `-css` part. So try just
   using `wiki-style`. It’s important to keep in mind though that this is telling
   WordPress that your stylesheet _depends_ on `wiki-style`. One thing this does
   is ensure that your stylesheet loads after `wiki-style`, but it also means that
   if `wiki-style` doesn’t load then neither will your stylesheet. This can happen
   if the plugin that loads those styles is deactivated, or if that plugin only 
   conditionally loads styles on certain pages.
 * In a situation where the purpose of your stylesheet is to overwrite a theme’s
   stylesheet styles you should set the dependency to be the _theme’s_ stylesheet.
   The handle for that should be the theme’s folder name.
 * A simpler way to load a stylesheet later is to set a higher priority for `add_action()`.
   The 3rd argument of `add_action()` is essentially the order that the hooks should
   occur. The default is 10, so using something like 99 will enqueue your stylesheet
   later than others:
 *     ```
       add_action('wp_enqueue_scripts','wpb_adding_styles', 99);
       ```
   
 * Aside from the order that stylesheets are loading the important thing to do is
   to make sure that your CSS rules are more _specific_ than the ones you are trying
   to overwrite. Read about Specificity in CSS [here](https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity).
 *  Thread Starter [VM06](https://wordpress.org/support/users/vm06/)
 * (@vm06)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/enqueue-style-and-scripts/#post-10532564)
 * Hello [@jakept](https://wordpress.org/support/users/jakept/),
    Thanks for your
   complete answer. I did not see it as I did not receive any notification. So, 
   the way I added the stylesheet is correct? Or do I need to set a dependency (
   sorry but I did not understand everything)? And another question please : I have
   to change the code of some of the theme files (like header.php, footer.php…).
   I know how to do when we create a child theme but not when we create a plugin
   to make modifications. How do we do with a plugin? Is it better to create a child
   theme to override those files and make the necessary modifications? Thanks 🙂.

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Enqueue style and scripts’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 8 replies
 * 3 participants
 * Last reply from: [VM06](https://wordpress.org/support/users/vm06/)
 * Last activity: [7 years, 10 months ago](https://wordpress.org/support/topic/enqueue-style-and-scripts/#post-10532564)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
