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

Joseph Anson
Joseph Anson
14,448 Points

Have I missed something? Why do we use php to include the stylesheets instead of a link tag in the html?

Why function instead of <link> ?

1 Answer

WordPress has a strong developer community. Thousands of people around the world design themes and write plugins for WordPress. To make sure that everything works properly and no one is stepping on another’s toe, WordPress has an enqueue script function. This function provides a systematic way of loading JavaScripts and styles. By using wp_enqueue_script function, you tell WordPress when to load a script, where to load it, and what are it’s dependencies. This allows everyone to utilize the built-in JavaScript libraries that comes bundled with WordPress rather than loading the same third-party script multiple times. It also helps reduce page load time and avoid conflicts with other themes and plugins.

Joseph Anson
Joseph Anson
14,448 Points

Oh right ok, I thought it would take longer to load the page for some reason. Thanks!!

Not a problem. It would take longer if you added the files inline. With WP_enqueue_scripts durring the WP load the styles and scripts are loaded during the actual WP load.