1

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?

10

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 and get_stylesheet_directory_uri. Is it just the filters that are applied? @toscho – Jamie Jan 11 '14 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 the template functions. – fuxia Jan 11 '14 at 1:19
  • 1
    It'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. – mrwweb Apr 5 '16 at 22:32
  • And where do you add said function? – Edward Jun 21 '17 at 15:28
  • @user3411192 In the functions.php. – fuxia Jun 21 '17 at 15:29
0

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 '16 at 20:18
  • For more information on Child Themes see codex.wordpress.org/Child_Themes – Eleanor Ellis Apr 6 '16 at 16:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.