Conditionally enqueue a widget’s script/stylesheet in HEAD (only when present on page!)

WordPress as a nice function is_active_widget that you can use in your __construct and test if the widget is present in the current page and add your scripts/styles based on that ex: function __construct() { parent::__construct(__CLASS__, ‘BasicWidget’, array( ‘classname’ => __CLASS__, ‘description’ => “This is a basic widget template that outputs text to the sidebar” … Read more

How to properly dequeue scripts and styles in child theme?

You are very nearer to the solution, because you are on the right path. Just to tweak a little bit: There are two such action hooks: wp_print_scripts, and wp_print_styles So the way you can do it, is: hook ’em differently: //Dequeue Styles function project_dequeue_unnecessary_styles() { wp_dequeue_style( ‘bootstrap-map’ ); wp_deregister_style( ‘bootstrap-map’ ); } add_action( ‘wp_print_styles’, ‘project_dequeue_unnecessary_styles’ … Read more

How can I get a list of all enqueued scripts and styles?

do_action doesn’t quite work like that. When you call do_action(‘crunchify_print_scripts_styles’) WP looks at its list of registered actions and filters for any that are attached to a hook called crunchify_print_scripts_styles and then runs those functions. And you probably want to remove this: add_action( ‘wp_enqueue_scripts’, ‘crunchify_print_scripts_styles’); … because you aren’t able to get the return result … Read more