Is there a way to get a list of widgets used? I have a plugin that conditionally loads styles and scripts when a widget is active using the the WordPress
is_active_widgetfunction, but that returns false since the widget is not in a sidebar.
And/or is there a global variable to indicate when we’re on a Page Builder page?
Thanks,
Chris
Hi Chris
There are 2 ways you can handle this. The way I do it with my widgets is to enqueue the scripts and styles in the actual widget function. Page Builder pre calls all these functions before the header (I guess this would be pre rendering) so all your scripts and styles will be available in the head.
Another option is to use the would be to use something like the following.
I haven’t double checked that code, but I’m fairly sure it’ll all work. At worst, just use a var_dump for $panels_data to double check what’s all in there.
Thanks, Greg. That function works well as a Page Builder equivalent of `is_active_widget`.
I am loading the scripts in the widget->display and I’m not sure why I was checking is_active_widget there so removing that helped.
But the real problem was that I was registering the scripts and styles in my plugin setup, then enqueueing them in the widget(s). Page Builder’s preloading seemingly happens before `wp_enqueue_scripts` so the scripts were not registered and therefore could not be enqueued and localized. Enqueing them entirely in the widget->display solves it.
My plugin is Strong Testimonials (http://wordpress.org/plugins/strong-testimonials/). After some more testing, I will add Page Builder to my 100% Compatible list.
Thanks for your help. Cheers on a great plugin!
Chris