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.
Opens WPIDE on
Code
$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 add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.