0

I noticed that if I don't explicitely enqueue my theme's main stylesheet and jQuery in my functions.php, these are loaded anyway. But perhaps it's better for some reason to enqueue them ? What is the right way of doing it ?

1

jQuery is there because something else, probably a plugin, enqueued it. The enqueue API won't load it twice, so if you need it you need to ask for it.

The "right way" is to tell WP what you need, and let WP work out the dependencies and duplicates.

Now, there is a rather large "but" here. I've seen plenty of WP installs that have a dozen style sheets and a too-long-to-count list of included javascript. If you want to slow a site down, this is a good way to do it. There is an efficient way to develop and distribute themes/plugins, and that is to use the enqueue process. There is an efficient way to operate a website, and that is to reduce the number of http requests to the absolute minimum needed. That's what caching systems do, and they sometimes hook into the (drumroll please) enqueue process.

1

For theme's main stylesheet: NO

Theme's main stylesheet is loaded by default. So, there is no need to enqueue it yourself.

For jQuery: YES

jQuery isn't loaded by default. Either you need to enqueue it yourself or set as dependencies to other scripts that you are loading. Otherwise it won't be loaded.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.