# Record the Page and Referrer in Gravity Forms

> Fills hidden Gravity Forms fields with the title and address of the page the form is on and the site the visitor came from, so you know the context of each entry.

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

## Code

```php
add_filter( 'gform_field_value_page_title', function ( $value ) {
    return '' !== (string) $value ? $value : wp_strip_all_tags( (string) get_the_title( get_queried_object_id() ) );
} );

add_filter( 'gform_field_value_page_url', function ( $value ) {
    $id = get_queried_object_id();

    return '' !== (string) $value ? $value : ( $id ? (string) get_permalink( $id ) : home_url( add_query_arg( array() ) ) );
} );

add_filter( 'gform_field_value_referrer_url', function ( $value ) {
    if ( '' !== (string) $value || empty( $_SERVER['HTTP_REFERER'] ) ) {
        return $value;
    }

    return esc_url_raw( wp_unslash( $_SERVER['HTTP_REFERER'] ) );
} );
```

## Notes

Allow dynamic population on hidden fields with the parameter names page_title, page_url or referrer_url.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Record the Page and Referrer in 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/
