Scripts enqueuing requirement.

Hi there!

I’ve just faced a message from a reviewer I haven’t seen before:

Please enqueue scripts with proper hooks and not within the templates, use functions.php or non-templates instead. http://envato.d.pr/grEhYl/2Nu4Yjom

These two lines are located in a .php file with blog related functions and I’m not really sure what is this about? I’m registering all these scripts in the theme’s functions.php file with a proper hook for the “wp_enqueue_scripts” action. I do not enqueue them directly in the functions.php file because that particular script is being used only for very specific blog post types so there is no reason to keep it loaded all the time. Isn’t it the purpose of the register_script and enqueue_script functions division?

Edit: Well, I think I found it. I didn’t realise that that bit of a code was indeed repeated in one of the theme’s template files. Hopefully that’s it!

Thank you,
F.

I think you must include it in functions.php and use something like this:

if ( 'video' == get_post_format() ):
//Here include wp_enqueue_scripts
endif;

It seems you added it in a “Self Hosted Video” named template file. You should put it in functions.php and enqueue.

It was within a template for a single portfolio post. The thing is that there are more conditionals before this particular scripts get enqueued - it’s not only the video post format but also a metabox field value. It would mean that I’d have to repeat all those ifs inside the functions.php file.

Anyways, there are few ways to get it sorted. Thank you for your replies. :slight_smile: