Unsubscribe/Opt-Out mobile number by URL

Updated on Dec 08, 2024

The subscribers can unsubscribe/Opt-Out from the SMS newsletter by URL https://yourdomain.com/?wpsms_unsubscribe=01111111111

Shorten URL By Bitly

Also, by enabling Bitly on the Setting page, you are able to shorten unsubscribing URLs too, here is an example of a shortened URL https://bit.ly/3x2esyx

How to send the Unsubscribe/Opt-Out link in welcome SMS?

You may include the Unsubscribe/Opt-Out link automatically in the welcome SMS? use the below filter in your functions.php theme.

/**
 * Modify the welcome SMS message
 *
 * @param $message
 * @param $mobile
 * @return string
 */
function sendUnSubscribeUrlInWelcomeSMS($message, $mobile)
{
    $message .= sprintf('\r\n Unsubscribe link: %s', WPSms()->newsletter()->generateUnSubscribeUrlByNumber($mobile));
    return $message;
}
add_filter('wpsms_welcome_sms_message', 'sendUnSubscribeUrlInWelcomeSMS', 10, 2);

To go to the new line, you can use %0A or \r\n depending on the SMS gateway provider.

How to customize the unsubscribe URL:

You may modify the ?wpsms_unsubscribe query string in the URL by using the below filter in your functions.php theme.

/**
 * Modify to unsubscribe query string
 *
 * @param $queryString
 * @return string
 */
function modifyUnSubscribeQueryString($queryString)
{
    $unsubscribe = 'unsubscribe';
    return $unsubscribe;
}
add_filter('wpsms_unsubscribe_query_string', 'modifyUnSubscribeQueryString');

CSRF Checking: “Access denied.” Error

If you encounter an “Access Denied” error when attempting to unsubscribe via URL, you will need to disable CSRF checking. Please visit our guide here to learn more.