PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Does GF have a conditional function to check if there is a form on the page?

  1. 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.

    Posted 11 years ago on Thursday June 13, 2013 | Permalink
  2. Richard Vav
    Administrator

    It is my experience that the Gravity Forms scripts and styles are only enqueued and included on a post/page if there is form embedded on the post/page, what method are you using to embed the forms, what versions of WordPress and Gravity Forms are you using, are you using any add ons.

    Posted 11 years ago on Thursday June 13, 2013 | Permalink