When dealing with a widget that is a custom post type, is there a way to detect when that widget is displayed, then check its post meta for any custom css and enqueue it in the head of the site?
This may sound a bit confusing so I will explain a little further.
I have a plugin that has custom post type 'widget'.
When I create a post from that custom post type widget, I can then load that post content from its widget, selecting the post content to display.
If my post has custom css that is stored in the post meta, the widget will display the css, but it is enqueued in the footer.
Is there a way to check for that widget, then check for it's post meta custom css, then enqueue that css in the head section of the website?
This is specifically for a Visual Composer plugin, but I see every author that enables Visual Composer post content to be displayed via a widget to enqueue the css in the footer. This gives errors in accordance to WC3 standards.
So I figured I would ask for for some expert help because obviously the authors collectively have not found a way to do so, but I just believe this has to be possible.
I believe it is possible for a couple reasons.
- I see caching plugins grab any plugins css, in the footer, inline or enqueued and then enqueue it in the head of the site. So I know that such methods can be done maybe in the shutdown priority, etc. ... somewhere detecting right before page render if there is custom css enqueued in the footer, then grabbing that and forcing it to display in the head.
- This plugin Google Fonts Optimizer does just that, in a way, but I'm not sure how to tweak is methodology to do this for my plugin. I'm knew to the methods used by this plugin and php classes. But Google Fonts Optimizer will check for all the enqueued Google Fonts, then optimize them all into one request and strip it and force it to show in the head. @ https://github.com/sigginet/google-webfont-optimizer/blob/master/google-webfont-optimizer.php
Here's a gist of the css file I am trying to get to do this, but it might give the total look needed into the file @ https://gist.github.com/NoahjChampion/9329f7301eef9f2619b4