Moderator
Jan Dembowski
(@jdembowski)
Forum Moderator and Brute Squad
I’m pretty sure that it doesn’t need a priority because that’s called via an add_action() call and that does have a priority argument.
https://codex.ww.wp.xz.cn/Function_Reference/wp_enqueue_style
Code example.
https://codex.ww.wp.xz.cn/Function_Reference/wp_enqueue_style#Using_a_Hook
So if you needed that loaded later try
add_action( 'wp_enqueue_scripts', 'theme_name_scripts', 15 );
With 15 being loaded after the default priority of 10.
You can find some really good examples at this site.
http://themeshaper.com/modify-wordpress-themes/
I think that exposing a load order/priority in wp_enqueue_styles will make it easier for everyone to comply with the team’s recommendation to use this function for adding stylesheet links to the HTML head.
Thanks for your workaround suggestion. I had not thought of that because I have not yet read enough code to learn I could do it that way. Instead, I called wp_enqueue_style from the last hook I could find before the style links are emitted. It is very kludgy, but it does use the recommended function call.
add_action('wp_head','AB_late_css',1);
function AB_late_css(){
$source = get_stylesheet_directory_uri().'/adjust_ABplugins.css';
wp_enqueue_style('adjust_ABplugins', $source);
}
Thanks for this post it was very helpful. I needed my parent theme style to be loaded between the enqueued boostrap style and the child theme style. The Parent theme overrides some bootstrap styles and the child overrides some parent style. Believing that enqueued style is the best practices, I registered the bootstrap style in the parent theme. Then the child theme uses the add_action method you showed in the child theme function with the priority argument set to 11. Then in the parent theme I use add_action to enqueue the theme style(which pulls in the child style).
examples:
parent theme functions.php
function register_scripts(){
...
wp_enqueue_style( 'bootstrap-css', get_template_directory_uri() . '/css/bootstrap/bootstrap.min.css' );
wp_enqueue_style( 'bootstrap-theme-css', get_template_directory_uri() . '/css/bootstrap/bootstrap-theme.min.css' );
....
}
add_action( 'wp_enqueue_scripts', 'register_scripts' );
function register_childcss() {
wp_enqueue_style( 'style-css', get_stylesheet_uri() );
}
add_action('wp_enqueue_scripts', 'register_childcss', 15);
child theme functions.php
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles', 11 );
function theme_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}
Please let me know if this is crazy, as I’m new to this.