- This topic has 16 replies, 3 voices, and was last updated 3 years, 1 month ago by
David.
-
AuthorPosts
-
August 8, 2022 at 7:24 am #2306778
Sebastian
Hey guys,
This is a strange one. I’m developing a local site, using the usual enqueue method for a child theme but the stylesheet is not even showing up in the head when I check the source. I have downloaded and used the files from generatepress.com and used it several times before without any issues.
Here’s the enqueue in functions.php:
function my_included_files() { wp_enqueue_style('my_main_styles', get_theme_file_uri('/build/assets/css/mystyle.css'), array()); } add_action('wp_enqueue_scripts', 'my_included_files');
What on earth is going on? Is there some recent update that could cause this perhaps?
Thank you!
August 8, 2022 at 8:13 am #2306978David
StaffCustomer SupportHi there,
for stylesheets in the child theme, you should use the:
get_stylesheet_directory_uri
instead ofget_theme_file_uri
https://developer.wordpress.org/reference/functions/get_stylesheet_directory_uri/
August 9, 2022 at 12:07 am #2307487Sebastian
I have tried both and neither does any difference for me I’m afraid. Besides, as I stated earlier, I have used this before without any problems? There must be something else creating the problem.
Sidenote: Why should I use get_stylesheet_directory_uri() in favour of the other? This is contradicting from what is said here.
Thanks
August 9, 2022 at 12:22 am #2307503Fernando Customer Support
get_stylesheet_directory_uri()
works for the Child theme. The other retrieves the parent uri.Can you try this:
function my_included_files() { wp_enqueue_style('my_main_styles', get_stylesheet_directory_uri() . '/build/assets/css/mystyle.css', array() ); } add_action('wp_enqueue_scripts', 'my_included_files');
August 9, 2022 at 12:40 am #2307519Sebastian
That is the ecxact code I’m using right now. I’m aware of the difference in syntax between the two. And actually, the WP code reference says “
get_theme_file_uri
retrieves the URL of a file in the theme”, and not the parent.Anyways, it does not work. Could me using the theme library have anything to do with this? This is SO frustrating.
If it at least did turn up but loaded before the parent theme files, that I’d understand. But not showing at all is really strange.August 9, 2022 at 1:50 am #2307582David
StaffCustomer SupportCan you share a link to the site ?
August 9, 2022 at 3:16 am #2307656Sebastian
Yes, I can share with you a LocalWP “Live link”: witty-verb.localsite.io
Login credentials are submitted in the private info area.August 9, 2022 at 3:17 am #2307658Sebastian
As of now I have copied > pasted all custom GP css code into my child theme css file. That’s why it looks so crappy.
August 9, 2022 at 3:22 am #2307661David
StaffCustomer SupportAny chance of a temporary admin login so i can see the backend ?
August 9, 2022 at 4:09 am #2307687Sebastian
Yes, of course. Please see the private info area again.
August 9, 2022 at 5:57 am #2307753David
StaffCustomer SupportI Activated the Child Theme.
On the front end developers tools i see a 404 error for this:https://your-domain.localsite.io/wp-content/themes/generatepress_child/build/assets/css/mystyle.css?ver=6.0.1
So the
get_stylesheet_directory_uri()
is doing it thing as that returns this part of the URL:https://your-domain.localsite.io/wp-content/themes/generatepress_child/
Can you confirm that these folders and the file exists in your child theme:
'/build/assets/css/mystyle.css'
August 9, 2022 at 6:05 am #2307762Sebastian
I’m sorry, I was trying to rename the file just to see if anything changed. Now, everything is back to normal again and yes, I can confirm that all is there.
August 9, 2022 at 6:20 am #2307779David
StaffCustomer SupportIs that fixed now ? As i see the
mystyle.css
loading on the frontend ?August 9, 2022 at 6:26 am #2307787Sebastian
Yes, now it is actually loading!? Why – all of a sudden?
However it’s loading before the parent theme css. When adding a high priority as the last argument, the linkrel disappears again. Do you have a proper solution for this?August 9, 2022 at 7:10 am #2307833David
StaffCustomer SupportYou can define a dependency when you enqueue the styles:
https://developer.wordpress.org/themes/advanced-topics/child-themes/#3-enqueue-stylesheet
For example we can make it dependent on the parent themes main style sheet which has a handle of:
generate-style
.See here:
By doing so WP will load your stylesheet after any dependencies.
Heres the updated code:function my_included_files() { $parent_style = 'generate-style'; wp_enqueue_style('my_main_styles', get_stylesheet_directory_uri() . '/build/assets/css/mystyle.css', array( $parent_style )); } add_action('wp_enqueue_scripts', 'my_included_files');
-
AuthorPosts
- You must be logged in to reply to this topic.