- This topic has 8 replies, 2 voices, and was last updated 4 years, 5 months ago by
David.
-
AuthorPosts
-
October 14, 2021 at 5:02 pm #1963840
Jeff
I’m working with an under-construction site, so I can’t give URL just now. But…
I want the styles.css file in my child theme to load AFTER various others.
I’m using the
$depsparameter withinwp_enqueue_style(), but it’s not working. I use and have used this approach often (successfully) with other themes.[I’m not trying to add a second topic to one post, but this seems related:]
Trying to debug this issue, I created a simple CSS file (nwb.css) with one rule in the child folder.
I added the wp_enqueue_style() code to functions.php in my child folder. Uploaded. Refreshed browser.
This new CSS file isn’t listed anywhere in view-source.Look forward to your help.
October 15, 2021 at 1:48 am #1964072David
StaffCustomer SupportHi there,
can you share the enqueue function you’re using ?
October 15, 2021 at 6:38 am #1964303Jeff
I have simplified things for diagnostic purposes.
This is currently in the child theme folder’s
functions.php:add_action( 'wp_enqueue_scripts', 'nwb_enqueue_styles' ); function nwb_enqueue_styles() { $deps = array( 'generate-style' ); wp_enqueue_style( 'jeff-styles', get_stylesheet_directory_uri() . '/nwb.css', $deps ); }It’s not working. The
jeff-stylesstylesheet appears abovegenerate-style.You can see it in action here:
https://willpowerengineering.com/test/October 15, 2021 at 7:14 am #1964332David
StaffCustomer SupportTry the method that Tom provides here:
https://generatepress.com/forums/topic/how-to-deactivate-default-styles/#post-1676329
October 15, 2021 at 7:23 am #1964338Jeff
Here’s my functions.php:
add_action( 'wp_enqueue_scripts', function() { wp_dequeue_style( 'generate-child' ); wp_enqueue_style( 'generate-child' ); }, 500 ); add_action( 'wp_enqueue_scripts', 'nwb_enqueue_styles' ); function nwb_enqueue_styles() { $deps = array( 'generate-style' ); wp_enqueue_style( 'jeff-custom-styles', get_stylesheet_directory_uri() . '/nwb.css', $deps ); }And here’s a snapshot of the view-source, which you can see yourself from the link in my previous post:
<link rel='stylesheet' id='jeff-custom-styles-css' <link rel='stylesheet' id='tablepress-default-css' <link rel='stylesheet' id='font-awesome-official-css <link rel='stylesheet' id='generate-child-css' href <link rel='stylesheet' id='font-awesome-official-v4s <style id='font-awesome-official-v4shim-inline-css'>October 15, 2021 at 7:28 am #1964344Jeff
By the way, when I removed ‘generate-child’ from the $deps array (making it empty), the result is similar; i.e., ‘generate-child’ loads after.
October 15, 2021 at 7:35 am #1964352David
StaffCustomer SupportSorry .. i completely jumped the gun there, i should have looked to see this was a separate styles sheet to the child themes styles. So you don’t need Tom’s code.
Try just increasing the priority of your
wp_enqueue_scriptseg.add_action( 'wp_enqueue_scripts', 'nwb_enqueue_styles', 500 ); function nwb_enqueue_styles() { $deps = array( 'generate-style' ); wp_enqueue_style( 'jeff-custom-styles', get_stylesheet_directory_uri() . '/nwb.css', $deps ); }And you shouldn’t require dependencies.
October 15, 2021 at 7:45 am #1964363Jeff
Dang. (What’s the emoticon for ’embarrassed’?)
Basic WordPress 101.
Sorry I even bothered you.
Thanks much.October 15, 2021 at 8:05 am #1964563David
StaffCustomer SupportNo problems – glad to be of help 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.