gravity_form_enqueue_scripts()

gravity_form_enqueue_scripts()

DescriptionUsageParametersExamplesPlacementSource Code

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 wp_head

Usage

gravity_form_enqueue_scripts( $form_id, $is_ajax );

Parameters

$form_id integer
The form ID of the targeted form.

$is_ajax bool
Specify true to use ajax form submission. Default value is false.

Examples

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

This script should be placed in the theme』s header.php file just before the wp_head() function is called.

Source Code

This filter is located in gravityforms.php

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注