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 trialbogdangewald
1,008 PointsLoading CSS Into WordPress. another way? I have seen some themes that css is loaded otherwise
I have seen some themes that css is loaded otherwise. for example: <link href="<?php bloginfo('stylesheet_directory');?>/css/bootstrap.css" rel="stylesheet">
What is the better Right Way? what's the difference? thanks in advance
1 Answer
Stephen Van Delinder
21,457 PointsThe correct way is to call all of your styles in functions.php with wp_enque_style. This makes code much easier to manage as your site grows and allows you to handle dependencies when necessary.
Hope this helps.
Cesar Gonzalez
17,443 PointsCesar Gonzalez
17,443 PointsThis seems counter-intuitive to how Wordpress handles the loading of styles. Realistically this approach can work, but I wouldn't call it the correct way to load styles into your theme.
Instead, from what I've seen, the most accepted method for loading styles, as well as scripts, into a Wordpress theme is by use of the wp_enqueue_style() function (or the wp_enqueue_script() function for scripts). Using this method will ensure that your styles and scripts do not have any compatibility issues that might be occur from the scripts that any plugins on your site might also load.
Here's a bit more documentation on the correct method for loading styles into a Wordpress theme.
https://developer.wordpress.org/themes/basics/including-css-javascript/