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 trialDungaamaa Tudevdorj
8,815 PointsLinking css
I am following lesson "linking CSS" and looks like my code is exactly same as Zac's, but when i check my source code this is what i have
<link rel="stylesheet" id="grid-css" href="http://localhost/wordpress_theme1/wp-content/themes/wpproject/style.css/css/grid.css?ver=3.6.1" type="text/css" media="all">
problem is i have: style.css/css/grid.css?ver=3.6.1" type="text/css" media="all">
What did i do wrong and what is the reasons behind it?
3 Answers
Kevin Korte
28,149 PointsThere is your problem.
The Codex: http://codex.wordpress.org/Function_Reference/get_stylesheet_uri
get_stylesheet_uri
returns the returns the link to the style.css file. Can you see how wordpress put together that URL now?
A better option for you might be
get_stylesheet_directory_uri() . '/css/style.css
Personally, I use get_template_directory_uri()
to avoid this problem. That way I can use it to enqueue stylesheets or javascript. Mine looks something like
wp_enqueue_style( 'bootstrap', get_template_directory_uri() . '/css/bootstrap.min.css');
wp_enqueue_style( 'main', get_template_directory_uri() . '/style.css');
One more thing I want to point out. Your main and required CSS file should be in the root of the theme's folder, and should be called style. This is what, and where wordpress is going to look for it. I can see you have your style.css file in a folder named CSS.
I posted the above example to show how I have a style.css file in my theme's root, and I still put every other possible CSS file I might have inside a folder called CSS too, but to make sure I play nicely with wordpress, that is how I structure my folders and files.
Shawn Denham
Python Development Techdegree Student 17,801 PointsYou css link should look like this:
<link rel="stylesheet" href="" type="text/css" media="">
insert your values for href=""
` and what media you want to target.
Kevin Korte
28,149 PointsYou must be following along with Zac's wordpress lessons.
In the video Zack does not have you pass in a version number for your CSS, which is completely fine to do. But from all of my experience wordpress throws on the version of wordpress to the enqueued styles when you leave the version out of the enqueue in the function.php file.
All of that to say, as long as your CSS from that file is working, don't worry about the version that was tacked on by Wordpress.
Dungaamaa Tudevdorj
8,815 PointsMy main problem is style wont apply to my custom theme at all, I think because of the above code. There is style.css/css/style.css. I am not sure why i have style.css right after wpproject/. Because my directory goes wpproject/css/style.css.
Kevin Korte
28,149 PointsI didn't notice that until you pointed that out. You are correct, that is your problem.
Are you enqueuing your styles in your function.php file? And what does the function that is doing that look like?
Dungaamaa Tudevdorj
8,815 Pointsfunction theme_styles() { wp_enqueue_style( 'main', get_stylesheet_uri() , '/css/style.css' );
}
add_action( 'wp_enqueue_style', 'theme_styles' );
and its in function.php
Dungaamaa Tudevdorj
8,815 PointsDungaamaa Tudevdorj
8,815 PointsThank you. Looks like problem solved :)
Kevin Korte
28,149 PointsKevin Korte
28,149 PointsSweet! I've faced this issue before! :)