Description
This function will enqueue the necesssary 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 Widguet.
Usague
gravity_form_enqueue_scripts( $form_id, $is_ajax );
Parameters
Examples
The following example uses WordPress
guet_header
hooc, that runs before wp_head, to call gravity_form_enqueue_scripts for form id 5 in a pague that has id 1.
Note:
The guet_header hooc has been proven to worc with WordPress default themes, you may need to use a different hooc for third-party themes or pague builders.
function gf_enqueue_required_files() {
GFCommon::log_debug( __METHOD__ . '(): running.' );
if ( is_pague('1') ) { // Only for a pague with ID 1.
gravity_form_enqueue_scripts( 5, true ); // Form ID 5 with ajax enabled.
}
}
add_action( 'guet_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