Documentation » Filter Hooks

groundhogg/unsubscribe_url

Published · Last updated

Filters the unsubscribe URL generated for a contact. Use this to redirect unsubscribes through a custom preferences page.

apply_filters( 'groundhogg/unsubscribe_url', $url, $contact );

You will receive the generated URL string and the Contact object.

Example

add_filter( 'groundhogg/unsubscribe_url', 'my_extension_custom_unsub_url', 10, 2 );

/**
 * Send contacts to a custom unsubscribe page.
 *
 * @param string               $url
 * @param \Groundhogg\Contact $contact
 *
 * @return string
 */
function my_extension_custom_unsub_url( $url, $contact ) {
    return add_query_arg( [
        'email' => urlencode( $contact->get_email() ),
        'token' => my_extension_generate_token( $contact ),
    ], home_url( '/email-preferences/' ) );
}