# Extra Merge Tags for Gravity Forms

> Adds {site_name}, {site_url}, {form_entry_count} and {current_year} merge tags you can use in Gravity Forms notifications and confirmations.

- Type: PHP
- Runs: Run everywhere
- Category: [Forms](https://wpide.com/library/category/forms/)
- Tags: gravity-forms, merge-tags, notifications
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/gf-custom-merge-tags/

## Code

```php
add_filter( 'gform_custom_merge_tags', function ( $tags ) {
    $tags[] = array( 'label' => 'Site name', 'tag' => '{site_name}' );
    $tags[] = array( 'label' => 'Site URL', 'tag' => '{site_url}' );
    $tags[] = array( 'label' => 'Entries in this form', 'tag' => '{form_entry_count}' );
    $tags[] = array( 'label' => 'Current year', 'tag' => '{current_year}' );

    return $tags;
} );

add_filter( 'gform_replace_merge_tags', function ( $text, $form, $entry, $url_encode = false, $esc_html = false ) {
    if ( false === strpos( (string) $text, '{' ) ) {
        return $text;
    }

    $values = array(
        '{site_name}'    => wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ),
        '{site_url}'     => home_url( '/' ),
        '{current_year}' => wp_date( 'Y' ),
    );

    if ( false !== strpos( $text, '{form_entry_count}' ) && is_array( $form ) && class_exists( 'GFAPI' ) ) {
        $values['{form_entry_count}'] = (string) GFAPI::count_entries( (int) $form['id'], array( 'status' => 'active' ) );
    }

    foreach ( $values as $tag => $value ) {
        if ( $esc_html ) {
            $value = esc_html( $value );
        }
        $text = str_replace( $tag, $url_encode ? rawurlencode( $value ) : $value, $text );
    }

    return $text;
}, 10, 5 );
```

## Notes

The tags appear in the merge tag menu of notification and confirmation editors.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Extra Merge Tags for Gravity Forms" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
