Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Oliver Denman
Oliver Denman
898 Points

CSS in style.css seems to have no effect

I'm building a theme from scratch.

I copied and pasted my css over from my static to style.css but it had no effect. However it does work when I load it via functions.php

My static stylesheet is based on bootstrap. Could that be the reason it's not having any effect? There's no errors in the console so I'm not sure what's going on.

For reference here's the functions.php code that fixed it.

function ond_theme_styles() {
        wp_enqueue_style('bootstrap_css', get_template_directory_uri().'/css/bootstrap.min.css');
        wp_enqueue_style('theme_css', get_template_directory_uri().'/css/theme.css');

The css in question is in the second file. Is there any obvious reason why the styles wouldn't load from style.css?

2 Answers

Erik McClintock
Erik McClintock
45,783 Points

Oliver,

In your function there, you are not calling style.css. Are you calling it in your header.php file?

Erik

Oliver Denman
Oliver Denman
898 Points

Duh! That's me making assumptions again.

As style.css is required for all themes, I assumed that WP imported automatically. I guess there's no harm in keeping theme.css and leaving style.css empty apart from the meta information.

Thanks for the answer.

Erik McClintock
Erik McClintock
45,783 Points

Absolutely! A lot of people use that method, actually; they leave style.css empty aside from the meta information, as it is required, then they'll create a css folder and their own custom css files to link in however they see fit.

Bonus points if you link to a minified version of your CSS (once the site is live, anyway; not necessarily during production, unless you've got a handy Grunt/Gulp file set up, or want to manually minify the CSS after every little tweak)! :)

Erik