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 From Bootstrap to WordPress Setup a Bootstrap Theme Add Bootstrap CSS via the functions.php File

Loading 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

Cesar Gonzalez
Cesar Gonzalez
17,443 Points

This 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/

1 Answer

The 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.