I was wondering if its possible to have my theme style.css
in a css
folder rather than in the root? I assume that the Theme Metadata has to be in the theme root, but could the actual styles be moved? Is this a piece of meta data I would add to the theme meta?
2 Answers
You can just register another stylesheet instead of style.css
:
add_action( 'wp_enqueue_scripts', 'enqueue_theme_css' );
function enqueue_theme_css()
{
wp_enqueue_style(
'default',
get_template_directory_uri() . '/css/default.css'
);
}
This is, in my opinion, better than using style.css
.
-
Your link is useful. THis leads me to wonder what the difference between
get_template_directory_uri
andget_stylesheet_directory_uri
. Is it just the filters that are applied? @toscho– JamieJan 11, 2014 at 1:13 -
2@JamieWright
template
refers to the parent theme if there is one.stylesheet
is the currently used theme. If you don’t write a child theme, use thetemplate
functions.– fuxia ♦Jan 11, 2014 at 1:19 -
1It's worth noting that style.css has to be in the root directory of the theme in order to register the theme with WordPress (to show up on Appearance > Themes). However, you don't have to use it to actually load styles.– mrwwebApr 5, 2016 at 22:32
-
-
Originally I said
You could make your child theme stylesheet import another stylesheet
@import url("subdirectory/file.css");*
But this was incorrect as this is no longer the preferred way to reference a style sheet.
Now, I have discovered a plugin that makes child's play of creating a child theme (please excuse the pun) https://wordpress.org/plugins/child-theme-configurator/
You could probably use this plugin to enqueue your other stylesheet. Might be worth having a look at the instructions to see if this is practical.
Hope this helps.
-
@import
is slow, because the browser has to parse the first stylesheet in order to obtain the URL. And please do not use hard-coded paths.wp_content
as well as the WordPress installation directory can be any name, so this is not portable code.– fuxia ♦Apr 5, 2016 at 20:18 -