# Save the Signup Page in a Mailchimp Merge Field

> Stores the URL of the page where someone subscribed in a Mailchimp merge field, so you can see which articles and landing pages grow your list.

- Type: PHP
- Runs: Run everywhere
- Category: [Plugin Integrations](https://wpide.com/library/category/integrations/)
- Tags: mailchimp, newsletter, attribution
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/mc4wp-signup-page-merge-field/

## Code

```php
$wpide_field = 'SIGNUPURL'; // Mailchimp merge field tag.

add_filter( 'mc4wp_subscriber_data', function ( $subscriber ) use ( $wpide_field ) {
    if ( ! is_object( $subscriber ) ) {
        return $subscriber;
    }

    $url = wp_get_referer();
    if ( ! $url && isset( $_SERVER['REQUEST_URI'] ) ) {
        $url = home_url( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) );
    }

    if ( $url ) {
        $subscriber->merge_fields = isset( $subscriber->merge_fields ) ? (array) $subscriber->merge_fields : array();
        $subscriber->merge_fields[ $wpide_field ] = esc_url_raw( strtok( $url, '#' ) );
    }

    return $subscriber;
} );
```

## Notes

Create a text merge field in your Mailchimp audience first and put its tag (e.g. SIGNUPURL) in $wpide_field.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Save the Signup Page in a Mailchimp Merge Field" 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/
