0

I have a couple of questions regarding enqueuing scripts and styles in custom plugin code.

I've recently come across plugin code where scripts were enqueued hooing into the template_redirect action hook while scripts were enqueued using the ss_css (I guess this is a custom action) and login_enqueue_scripts action hooks.

My question, therefore, is:

What is the most appropriate hook to enqueue JS scripts and styles. Is it wp_enqueue_scripts as is the case in themes? Or should it be more purpose specific as in the scenario described above? In short, should enqueuing scripts and styles in plugins be governed by different rules?

2

Straight outta the Codex:

wp_enqueue_scripts is the proper hook to use when enqueuing items that are meant to appear on the front end. Despite the name, it is used for enqueuing both scripts and styles.

So the simple answer to your question is yes, wp_enqueue_scripts is always the correct action for enqueuing scripts AND styles. This is so other themes/plugins can modify previously-enqueued files or other plugins (e.g. a minifier) can assume that all scripts/styles are loaded with that hook.

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.