Using Gravity Forms ‘gform_form_after_open’ PHP filter

The gform_form_after_open filter allows you to add markup directly after the opening form wrapper in Gravity Forms.

Usage

Apply to all forms:

add_filter('gform_form_after_open', 'your_function_name', 10, 2);

Target a specific form by appending the form ID to the hook name (format: gform_form_after_open_FORMID):

add_filter('gform_form_after_open_10', 'your_function_name', 10, 2);

Parameters

  • $markup (string) – The current string to append.
  • $form (Form Object) – The form currently being processed.

More information

See Gravity Forms Docs: gform_form_after_open

Examples

Add a subtitle after the form opening

This example adds a subtitle right after the form opening.

add_filter('gform_form_after_open', 'add_subtitle_after_open', 10, 2);
function add_subtitle_after_open($markup, $form) {
    $subtitle = __('This is a subtitle.', 'your-text-domain');
    $html = sprintf('<h3>%s</h3>', $subtitle);

    return $markup . $html;
}

Add a custom container after the form opening

This example adds a custom container right after the form opening.

add_filter('gform_form_after_open', 'add_custom_container', 10, 2);
function add_custom_container($markup, $form) {
    $html = '<div class="custom-container">';

    return $markup . $html;
}

Add a progress indicator after the form opening

This example adds a progress indicator after the form opening.

add_filter('gform_form_after_open', 'add_progress_indicator', 10, 2);
function add_progress_indicator($markup, $form) {
    $html = '<div class="progress-indicator"></div>';

    return $markup . $html;
}

Add a custom message for a specific form

This example adds a custom message for a specific form with the ID of 5.

add_filter('gform_form_after_open_5', 'add_custom_message', 10, 2);
function add_custom_message($markup, $form) {
    $message = __('Please fill out the form below.', 'your-text-domain');
    $html = sprintf('<p>%s</p>', $message);

    return $markup . $html;
}

Add an image after the form opening

This example adds an image after the form opening.

add_filter('gform_form_after_open', 'add_image_after_open', 10, 2);
function add_image_after_open($markup, $form) {
    $image_url = 'https://example.com/path/to/image.jpg';
    $html = sprintf('<img src="%s" alt="Example Image">', $image_url);

    return $markup . $html;
}