Using Gravity Forms ‘gform_postimage_caption’ PHP action

The gform_postimage_caption filter allows you to modify the “Caption” label of the Post Image Caption field in Gravity Forms.

On this pageJump to a section

Usage

To apply your custom function to all forms, use the following code:

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

To target a specific form, append the form ID to the hook name:

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

Parameters

  • $label (string): The label to be filtered.
  • $form_id (integer): The current form’s ID.

More information

See Gravity Forms Docs: gform_postimage_caption

Examples

Change the default Post Image Caption label

This example modifies the default Post Image Caption label:

add_filter('gform_postimage_caption', 'change_postimage_caption', 10, 2);

function change_postimage_caption($label, $form_id) {
    return 'Image Caption';
}

Change the label for a specific form

This example modifies the Post Image Caption label for the form with ID 3:

add_filter('gform_postimage_caption_3', 'change_caption_form_3', 10, 2);

function change_caption_form_3($label, $form_id) {
    return 'Custom Caption';
}

Change the label based on form ID

This example modifies the Post Image Caption label differently for forms with IDs 1 and 2:

add_filter('gform_postimage_caption', 'change_caption_based_on_form', 10, 2);

function change_caption_based_on_form($label, $form_id) {
    if ($form_id == 1) {
        return 'Caption Form 1';
    } elseif ($form_id == 2) {
        return 'Caption Form 2';
    }
    return $label;
}

Change the label with a prefix

This example adds a prefix to the Post Image Caption label:

add_filter('gform_postimage_caption', 'add_prefix_to_caption', 10, 2);

function add_prefix_to_caption($label, $form_id) {
    return 'Prefix - ' . $label;
}

Change the label with a suffix

This example adds a suffix to the Post Image Caption label:

add_filter('gform_postimage_caption', 'add_suffix_to_caption', 10, 2);

function add_suffix_to_caption($label, $form_id) {
    return $label . ' - Suffix';
}

Leave a Comment

Your email address will not be published. Required fields are marked *

Type guide in lowercase to submit your comment.