How to load Widget javascript + css files only if used?

wp_print_scripts and wp_print_styles hooks are fired way before your widget function so that is way it’s not working.

A solution to that would be to include the scripts in the footer using wp_print_footer_scripts hook, take a look at Jan’s answer to a similar question

Or a much nicer solution take a look at Sorich’s answer to another similar question

Leave a Comment