I'm looking for a good way to only load the GF CSS and JS files if there is a form on the page. Many times there are only one or 2 pages on the site with a form, and it wold be nice not to have to load all of those files on pages where they're not needed.
I have gone the route of toggling "Output CSS" to "No" in settings, registering my own copy of the stylesheet, and then conditionally enqueueing it on a per page basis:
// Register Gravity Forms style sheet
wp_register_style( 'gravity-forms', get_stylesheet_directory_uri() . '/library/css/gravity-forms.css', array(), '' );
// Only load it on Contact Us page
if(is_page('contact-us')){
wp_enqueue_style('gravity-forms');
}
but that is prone to breaking if the page with the form on it changes, a new form is added somewhere else, etc.
It would be awesome to have a is_gforms
conditional to use.