Is the code below really needed if i am using
get_theme_file_uri()
in
my parent theme as it will automatically search for file in child
theme?
No. If your parent theme uses get_theme_file_uri( '/style.css' )
, then when you create a style.css file in your child theme, WordPress will load that instead. So it won’t load the parent theme’s styles at all, which I think is related to your next question.
I have some css code in parent theme (style.css). So if i use child
theme(which is empty). so whether the parent theme style will get
applied?
If your parent theme uses get_theme_file_uri( '/style.css' )
, and your child theme has a style.css file, the parent the styles won’t get loaded at all. get_theme_file()
will load the first file it finds, not all of them.
If you want to load the parent theme’s styles and the child theme’s styles, you have two options:
- Update your parent theme to use
get_parent_theme_file_uri( 'style.css' )
. This will cause WordPress to always load style.css from the parent theme, even if a child theme is activated. If you want to load style.css from the child theme as well, then enqueueget_theme_file_uri( 'style.css' )
from the child theme. Or, - Leave your parent theme the way it is, and then enqueue the parent theme’s stylesheet from the child theme by enqueueing
get_parent_theme_file_uri( 'style.css' )
from the child theme.