Title: Code for unsubscribe
Last modified: March 26, 2019

---

# Code for unsubscribe

 *  Resolved [steve92](https://wordpress.org/support/users/steve92/)
 * (@steve92)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/code-for-unsubscribe/)
 * I’m customizing the code and I want to give an extra option to the subscriber,
   what code do I put here?
 * ![](https://i0.wp.com/i67.tinypic.com/2z8x3sp.png)

Viewing 8 replies - 1 through 8 (of 8 total)

 *  [Matt Robinson](https://wordpress.org/support/users/mattyrob/)
 * (@mattyrob)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/code-for-unsubscribe/#post-11359464)
 * [@steve92](https://wordpress.org/support/users/steve92/)
 * That’s not code, that’s an email template. You can’t put code in there but you
   can use the existing keywords listed on the right or create your own {CUSTOM_KEYWORD}
   using the plugin ‘s2_custom_keywords’ hook as documented [here](https://subscribe2.wordpress.com/support/api/).
 *  Thread Starter [steve92](https://wordpress.org/support/users/steve92/)
 * (@steve92)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/code-for-unsubscribe/#post-11359553)
 * Where I put this code?
 *     ```
       function bitly_keyword( $string, $token = 'PUT YOUR API TOKEN HERE') {
           global $mysubscribe2;
           $link = $mysubscribe2->get_tracking_link( $mysubscribe2->permalink );
           $bitlydata = wp_remote_get('https://api-ssl.bitly.com/v3/shorten?access_token=' . $token . '&longUrl=' . urlencode($link));
           $data = json_decode( wp_remote_retrieve_body( $bitlydata ) );
           if  ( 'ok' === strtolower($data->status_txt) && 200 === (int)$data->status_code ) {
               $bitlylink = '<a>data->url . '">' . $data->data->url . '</a>';
           } else {
               $bitlylink = '<a href="' . $link . '">' . $link . '</a>';
           }
           return str_replace('{BITLYLINK}', $bitlylink, $string);
       }
       add_filter('s2_custom_keywords', 'bitly_keyword');
       ```
   
 * I think you can put a default code like {unsubscribe}
 *  [Matt Robinson](https://wordpress.org/support/users/mattyrob/)
 * (@mattyrob)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/code-for-unsubscribe/#post-11361028)
 * [@steve92](https://wordpress.org/support/users/steve92/)
 * Either in your themes functions.php file or better still create your own custom
   site plugin to ensure your changes won’t be lost if the Theme is updated.
 * If you’ve never created a plugin before use Pluginception – it sets things up
   niceley for you to just add the code.
 *  Thread Starter [steve92](https://wordpress.org/support/users/steve92/)
 * (@steve92)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/code-for-unsubscribe/#post-11361035)
 * Ok. I put this in functions.php file child, then what I do?
 *     ```
       function bitly_keyword( $string, $token = 'PUT YOUR API TOKEN HERE') {
           global $mysubscribe2;
           $link = $mysubscribe2->get_tracking_link( $mysubscribe2->permalink );
           $bitlydata = wp_remote_get('https://api-ssl.bitly.com/v3/shorten?access_token=' . $token . '&longUrl=' . urlencode($link));
           $data = json_decode( wp_remote_retrieve_body( $bitlydata ) );
           if  ( 'ok' === strtolower($data->status_txt) && 200 === (int)$data->status_code ) {
               $bitlylink = '<a>data->url . '">' . $data->data->url . '</a>';
           } else {
               $bitlylink = '<a href="' . $link . '">' . $link . '</a>';
           }
           return str_replace('{BITLYLINK}', $bitlylink, $string);
       }
       add_filter('s2_custom_keywords', 'bitly_keyword');
       ```
   
 *  [Matt Robinson](https://wordpress.org/support/users/mattyrob/)
 * (@mattyrob)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/code-for-unsubscribe/#post-11363485)
 * [@steve92](https://wordpress.org/support/users/steve92/)
 * That code specifically allows you to use a {BITLYLINK} keyword in the body of
   the email notification to include links to your posts that have been shortened
   using the Bit.ly URL shortener.
 * You would need to create some code the implements the additional functionality
   your briefly described in your original post.
 *  Thread Starter [steve92](https://wordpress.org/support/users/steve92/)
 * (@steve92)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/code-for-unsubscribe/#post-11363766)
 * Ok, maybe I didn’t explain myself: I need a code that the user clicks and cancels
   his registration.
    Eg: “If you want to cancel your subscription click here: {
   code}”
 *  [Matt Robinson](https://wordpress.org/support/users/mattyrob/)
 * (@mattyrob)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/code-for-unsubscribe/#post-11365293)
 * [@steve92](https://wordpress.org/support/users/steve92/)
 * That feature is available in Subscribe2 HTML as an extra feature.
 * If you want to create this yourself you’d need to create code using the snippet
   example above to create a keyword that inserts a link into the email notification
   that is unique for each email recipient.
 * After that is done and working you’d need to handle users clicking on those links
   and process the request on your site with a bit more code linking into the Subscribe2
   unsubscribe functions.
 *  Thread Starter [steve92](https://wordpress.org/support/users/steve92/)
 * (@steve92)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/code-for-unsubscribe/#post-11365316)
 * I’m not able to do it. You could put it in the next version.

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Code for unsubscribe’ is closed to new replies.

 * ![](https://ps.w.org/subscribe2/assets/icon-256x256.png?rev=2318630)
 * [Subscribe2 - Form, Email Subscribers & Newsletters](https://wordpress.org/plugins/subscribe2/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/subscribe2/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/subscribe2/)
 * [Active Topics](https://wordpress.org/support/plugin/subscribe2/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/subscribe2/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/subscribe2/reviews/)

 * 8 replies
 * 2 participants
 * Last reply from: [steve92](https://wordpress.org/support/users/steve92/)
 * Last activity: [7 years, 2 months ago](https://wordpress.org/support/topic/code-for-unsubscribe/#post-11365316)
 * Status: resolved