gform_pre_replace_merge_tags

Description

Use this filter to replace default merge tags before they are replaced by GFCommon::replace_variables().

Usage

add_filter( 'gform_pre_replace_merge_tags', 'replace_custom_merge_tags', 10, 7 );

Parameters

  • $text string

    The current text in which merge tags are being replaced.

  • $form Form Object

    The current form.

  • $entry Entry Object

    The current entry.

  • $url_encode boolean

    Whether or not to encode any URLs found in the replaced value.

  • $esc_html boolean

    Whether or not to encode HTML found in the replaced value.

  • $nl2br boolean

    Whether or not to convert newlines to break tags.

  • $format string

    Determines how the value should be formatted. Default is html.

Examples

1. Replace {form_title}

This example shows how you can replace the {form_title} merge tag with your own custom text.

add_filter( 'gform_pre_replace_merge_tags', function ( $text, $form, $entry, $url_encode, $esc_html, $nl2br, $format ) {
	$merge_tag = '{form_title}';

	if ( strpos( $text, $merge_tag ) === false || empty( $form ) ) {
		return $text;
	}

	return str_replace( $merge_tag, 'Your Custom Text', $text );
}, 10, 7 );

Source Code

apply_filters( 'gform_pre_replace_merge_tags', $text, $form, $entry, $url_encode, $esc_html, $nl2br, $format )

This filter is located in GFCommon::replace_variables() in common.php.

Since

This filter was added in Gravity Forms 1.9.6.