wp enqueue style and style sheet depth

You can add a priority number to the wp_enqueue_scripts action. So you could could give the action hooked to the enqueue of yourstyle sheet a priority of 999. Like so:

function high_priority_style() {
  Wp_enqueue_style('important', get_template_directory_uri() . '/css/important.css');
}
add_action('wp_enqueue_scripts', 'high_priority_style', '999');

A simpler way to do is enqueue all of your stylesheets, including style.css in the same function, hooked to wp_enqueue_scripts and they will be added in the order that they appear in the function, like this:

  function styles() {
  wp_enqueue_style('low-priority', get_template_directory_uri() . '/css/low-priority.css');
  wp_enqueue_style('theme', get_template_directory_uri() . '/style.css');
  wp_enqueue_style('important', get_template_directory_uri() . '/css/important.css');
}
add_action('wp_enqueue_scripts', 'styles');

I included a lower priority stylesheet in this example, that would be something like the CSS for a framework or grid system.

Make sure to remove any hard coded links to any stylesheets in header.php when adding styles this way (ie the right way.)

Leave a Comment