Description
This function will enqueue the necessary styles and scripts for the specified Gravity Form. This is useful when manually embedding a form outside the WordPress loop using the function call or to force the stylesheets and scripts to load in the header when using the Form Widget.
Note: To correctly enqueue the scripts, this function must be called before execution of wp_head
Usage
gravity_form_enqueue_scripts( $form_id, $is_ajax );
Parameters
Examples
The following example uses WordPress get_header hook, that runs before wp_head, to call gravity_form_enqueue_scripts for form id 5 in a page that has id 1.
function gf_enqueue_required_files() {
GFCommon::log_debug( __METHOD__ . '(): running.' );
if ( is_page('1') ) { // Only for a page with ID 1.
gravity_form_enqueue_scripts( 5, true ); // Form ID 5 with ajax enabled.
}
}
add_action( 'get_header', 'gf_enqueue_required_files' );
Placement
gravity_form_enqueue_scripts must be called before wp_head execution, an easy way to do this is to put the script in the theme’s header.php file just before the wp_head()
function is called.
Source Code
This filter is located in gravityforms.php