Turn your commenters into subscribers!

Only a small percentage of your visitors leave a comment. This group of people is probably also interested in subscribing to your newsletter, if you have one. So I created a method to add a “subscribe to my SEO newsletter” checkbox to my comment form a couple of weeks ago. The result? 40 new subscribers in less than 2 weeks. That’s over 1,000 new subscribers each year if it continues to grow in this fashion.

This isn’t for the faint of heart, if you’re not a programmer this might be a bit tough to do, but I’ll outline how it works:

Adding a comment meta value

Using the reasonably new comment_meta API, we’re gonna add a piece of data to comments, that stores whether people want to subscribe to the newsletter or not. I did that by adding the following function to my functions.php file:

function ymc_add_meta_settings($comment_id) {
add_action ('comment_post', 'ymc_add_meta_settings', 1);

Add a checkbox to the comment form

That wasn’t too hard yet right? Next we add the checkbox to the comment form, wherever that is located in your theme, it’s just plain (X)HTML:

<input type="checkbox" name="mailchimp_subscribe" 
<label for="mailchimp_subscribe">
  Subscribe to Yoast WordPress Newsletter (weekly email)

Subscribe the commenter

That’s not really rocket science either. The next step is to take this data and work it. What we’ll do is use the Mailchimp API to automatically subscribe people, and send them a confirmation email (we still need to make sure they double-opt-in).

First, let’s grab the comment:

function ymc_subscription_add( $cid, $comment ) {
  $cid = (int) $cid;
  if ( !is_object($comment) )
    $comment = get_comment($cid);
  if ( $comment->comment_karma == 0 ) {
    // DO WORK
add_action('comment_post', 'ymc_subscription_add', 60,1);

The code above makes sure we only do anything with comments that have been approved. So if a comment is approved as spam, it gets ignored. It also makes sure the $comment variable is filled with the comment. Now once we’ve done this, we’re going to check whether the commenter wanted to be subscribed to the newsletter, so within the DO WORK section above, we add this:

$subscribe = get_comment_meta($cid, 'mailchimp_subscribe', true);
if ( $subscribe == 'on' ) {
  // DO WORK

We’re checking for “on” because that’s how PHP stores a checked checkbox, and this way we can reuse the $subscribe variable later. Once we’re sure the commenter wanted to be subscribed, let’s get all the data we need to add a subscriber to our mailing list. To do that, we’ll need to know:

Once you’ve got these three, we can create the post request:

$apikey   = ' <your API key> ';
$listid   = ' <List ID> ';
$endpoint   = 'http://<your endpoint>.api.mailchimp.com/1.3/?output=php';

$request   = array(
  'apikey' => $apikey,
  'id' => $listid,
  'email_address' => strtolower( $comment->comment_author_email ),
  'double_optin' => true,
  'merge_vars' => array(
    ' <merge tag for name> ' => $comment->comment_author,
    'OPTIN_IP' => $comment->comment_author_IP,
$result = wp_remote_post(
  array( 'body' => json_encode($request) ) 

Note: setting double_option to false would forego the sending of an opt-in email, thereby immediately subscribing people to the list. Do not do this as it is illegal in most parts of Europe and in the US to do so.

As you can see, we’re using the WP_HTTP wrapper function wp_remote_post to handle the post. At this time I’m not actually doing anything with the result, because I’m a sloppy coder. You should of course check the result and based on that do the following action:

update_comment_meta($cid, 'mailchimp_subscribe', 'subscribed', 'on');

This will prevent the code from trying to subscribe someone multiple times and overloading the MailChimp API.

Conclusion: Subscribe those commenters!

People are interacting with your site already, they’re already giving you their email address, have them check that box, and make them subscribe to your list. I personally think it’s a great enhancement that would make a lot of people happy. If you’re not using Mailchimp but another email provider and are capable to do the same stuff with their API: please post about it, drop a comment here and I’ll add a link!

Disclosure: Mailchimp sponsors my newsletter and is a regular advertiser on my sites.

Make Yoast SEO & Woo work together smoothly

  • Make your products stand out in Google
  • Get more buyers to your online store
  • Make products easier to find on your site
  • Have a cleaner XML sitemap & more
More info

64 Responses to Turn your commenters into subscribers!

  1. w3expose
    w3expose  • 8 years ago

    Have anyone of you guys implemented this on a Genesis framework Child theme?

  2. Scott
    Scott  • 8 years ago

    Thanks for the great tip and article. I’m slowly figuring this out and was wondering if there is a way to do the comment.php portion with just a hook inside functions.php instead of modifying the actual theme file?

  3. Mark
    Mark  • 8 years ago

    Hi Yoast,

    Thanks for giving so much great usable content and tips etc.

    Will keep following your blog; thanks again!

  4. SGr33n
    SGr33n  • 8 years ago

    Great idea! I’m commenting, I will also subscribe to your newsletter :p
    Anyway maybe better to check it by default :p

  5. Cory Matheson
    Cory Matheson  • 8 years ago

    I am currently revamping my website and I installed Bhu_C2S to my WordPress blog. I have a mailchimp account as well and added all of the info needed in order to activate this plugin. However, I am not seeing any area to comment on the blog posts, nor am I seeing the ‘opt in’ button/option that I was hoping this plugin would provide.

    Wondering if there is something else that I need to do here in order to have the comment box and ‘opt in’ option showing on my posts. My website is currently a dev site until I can get this issue fixed. I may have to switch to another plugin if I can’t get this to work. Thanks

  6. Russell Thackston
    Russell Thackston  • 8 years ago

    Awesome idea!

    I’ve implemented it on both my websites. Only took a few minutes. It was actually easier to follow your code example than it was to install and configure the plug-in! Works like a charm.

    And, by the way… I subscribed to your newsletter.

  7. Hudson
    Hudson  • 8 years ago

    Would love an aweber plugin that does this.

  8. wilson usman
    wilson usman  • 8 years ago

    I’m confused because I have Thesis Theme. Do I just copy and past most of the code on the custom_functions.php?

  9. Arjen
    Arjen  • 8 years ago

    Nice idea! How popular is mailpress as newsletter??? I would love to see an integration with that service too.

  10. Azzam Sheikh
    Azzam Sheikh  • 8 years ago

    There is an existing plugin that already exist that works for AWeber, Mailchimp, Feedblitz, etc.

    I have wrote a follow up blog post to this and added the links to the plugin with a few of my thoughts:


    • Adam W. Warner
      Adam W. Warner  • 8 years ago

      Azzam, great write up and wow, this plugin seems like it “has it all”…going to test now. Thanks for letting us all know!

      • Adam W. Warner
        Adam W. Warner  • 8 years ago

        I have not been able to get this to work as expected so far. I am using MailChimp and have followed the plugin author’s directions, but so far no confirmation emails are getting sent.

        I’m going back to Bhu_C2S for now, it worked as expected right away, although I would like to see more features, it does the job:)

        • Azzam Sheikh
          Azzam Sheikh  • 8 years ago

          That is a real shame that it did not work.
          Did you check the forum over at wordpress for some already answered support?
          Obviously if the Bu_C2S version has worked then there is no need for you to take it any further.

          If bhuthecoder wants to combine it with his so it is working for all services including feed-burner that would be awesome and I could do another rewrite.

          I would like to see the option of a friendly pop-up if the text hits a blind spot and the commentator is prompted again

  11. Ronen Bekerman
    Ronen Bekerman  • 8 years ago

    Great stuff going on here!

    After reading this and hearing Yoast’s and Frank’s latest Podcast – How To Grow The Engagement On Your Blog

    Subscribers are not just email subscribers! I’m trying to increase my twitter followers just as much since I found that they respond very well to my tweets and do come visiting my blog & forums each time a send one out and engage with the new post / thread for a few minutes each time generating feedback and… you catch my drift :-)

    For a time the followers number increased in a steady rate, but lately seemed to hit a “glass ceiling” – not sure why is that yet (same for RSS actualy), the email subscribe rate keeps getting higher & higher.

    After reading Avinash Kaushik article (recommend on the aforementioned podcast page – so do check it out!) in his 9th recommendation he suggest to tweet the fact you comment about a topic on a blog.

    Any chance this latest plugin can be expanded to allow for following a twitter account and tweet the fact you just now commented about something with a link back to it?

    I’ve seen some implementations like – http://ttc.readscott.com/ but i don’t think the popover approach is very good… I much rather have it all done backstage in code and send it out with the comment submit button.

    Any thoughts about that?

  12. Bakkel
    Bakkel  • 8 years ago

    PLugin installed (great work btw), but the option isn’t showing up under my commentform. I use thesis framework, so I think I have to manually put the code in. My question: What is the code??

    • bhuthecoder
      bhuthecoder  • 8 years ago

      I just placed the code.You can copy the code from here : http://www.bhuthecoder.com/plugins/bhu_c2s/

      You can copy the code into your comments template

      • Bakkel
        Bakkel  • 8 years ago

        Code works like a charme! thx!!

        For anyone using Thesis:

  13. Sean Daily
    Sean Daily  • 8 years ago

    Very excited about this plugin and thanks for making it Bhu. Unfortunately, it’s not working on my 2 sites running the ThemeShift deVision template. =(

  14. bhuthecoder
    bhuthecoder  • 8 years ago

    HI all.
    I converted this code into a plugin.and tested with 3.04 version.soon i will add more services like feedburner,awber depending on people response.
    here the link : http://www.bhuthecoder.com/plugins/bhu_c2s/ or http://wordpress.org/extend/plugins/bhu-c2s/

    • Herman dailybits
      Herman dailybits  • 8 years ago

      +1 for feedburner support for this plugin…

    • Andre Stoelinga
      Andre Stoelinga  • 8 years ago

      It would be awesome if you’d be able to integrate more AR services. I’m using Imnica Mail since recently. Same features and reporting as aweber and they’ve overhauled the whole system. I hope you can find a way to include Imnica in your plugin… I get so many new users daily, it would be perfect to get some subscribers out of it…


    • Ronen Bekerman
      Ronen Bekerman  • 8 years ago

      Cool! Thanks… If someone else is loading this – please add your feedback to it.

  15. Natalie Sisson
    Natalie Sisson  • 8 years ago

    What if you have Livefyre commenting system on your blog – I assume this won’t work with it?


  16. Hendrik
    Hendrik  • 8 years ago

    Awesome idea. that s for sure. I already use AutoChimp plugin to ask our users to subscribe to our newsletter.

    This way is pretty elegant, though.

    Is there a way that the user sees a checkbox asking him whether he wants to create an account on that website?

  17. Simin Lim
    Simin Lim  • 8 years ago

    I think it can be more easier if it is a plugin =D
    And change the Mailchimp to feedburner. Thanks :D

  18. rightways
    rightways  • 8 years ago

    Yoast, great idea!

    Can you provide me with a plugin or a short code?


  19. Bill (LoneWolf) Nickerson
    Bill (LoneWolf) Nickerson  • 8 years ago

    Anyone have a look at how this would work with the new AWeber API if possible? I plan on looking into this at some point, but if someone else has done the heavy lifting …

    Thanks for the work you’ve done on this Joost!

    • Lars Koudal
      Lars Koudal  • 8 years ago

      This is the code I have used in the past:


      Replace ‘%email%’ with the e-mail to subscribe and the three other variables YOUR_FORM_ID, YOUR_LIST_ID and YOUR_REDIRECT_URL with your own.

      • Bill (LoneWolf) Nickerson
        Bill (LoneWolf) Nickerson  • 8 years ago

        The problem with this solution is that it would be called from your server rather than the user’s computer. That is a violation of AWeber’s terms. You can use this as the action of a form but not from a script on the server.

        I ran into this when I was looking at joining a giveaway event that was attempting to streamline the member signup process. They already had the name and email address when the user signed up for the event so they just passed it through the script. AWeber didn’t like it since it breaks the audit trail for signups.

        As I see it, there are a couple of options:
        1) Use JavaScript to hook the Post button (onSubmit) for the comment form and call the addlead.pl at that point if the checkbox is checked. This doesn’t get the benefit of spam filtering though. Do robots check boxes when they submit a spam comment?
        2) Have the comment code redirect to another page with a form to submit to AWeber. I’m not sure if you can “auto submit” that form or if the user would need to click on a button. That could then take them back to the original article.

        There are likely other options that will work as well. I wish I had more time to work on this right now, but it will have to wait a couple of days. Perhaps someone else will find a solution in the mean time.

  20. Sean
    Sean  • 8 years ago

    +1 for the plugin idea.. and fantastic post Joost!

  21. Fred Leo
    Fred Leo  • 8 years ago

    Does anyone know if this will work with Aweber?

    • Lars Koudal
      Lars Koudal  • 8 years ago

      Hi Fred

      Yes it will. Aweber offers API integration. To be honest its been over a year since I tested it, but I doubt they have removed functionality in the mean time :-)

  22. pete
    pete  • 8 years ago

    Good idea! Could it be a plugin for WordPress? Or maybe a post on WordPress Comments/trackbacks best practice …

    spam and suchlike is 95% of my ‘comments awaiting moderation :(

  23. Ivan Vucic
    Ivan Vucic  • 8 years ago

    While we are on the note about subscribing and that stuff, i noticed when i added feedburner to some of my blogs they dropped in se and got some penalties, do you have some experience with it?

  24. Lars Koudal
    Lars Koudal  • 8 years ago

    Haha Joost

    Perfect timing, lol! I have been working on re-releasing my newsletter plugin the past few days, and now I read this post by you! :-)

    Oh well, I guess I still have the market of WordPress uses who are not comfortable doing those changes manually.

    Great post as always, and I’m happy to see the life-style change seems to suit you :-)

    Best wishes from Barcelona.

  25. Zane Dickens
    Zane Dickens  • 8 years ago

    This is great idea! Thanks for the share. Its definitely being added to my list of urgent things to add to my blog.

    +1 for the plugin – even if its premium.

  26. Phillip Dews
    Phillip Dews  • 8 years ago

    Hi Joost,

    sounds like a great tip1 will be using this for sure! saying that though I am using Aweber and not mailchimp! will this work for Aweber as well? and how do I go about changing the code?

    thanks for this great tip!
    -Phillip Dews

  27. Tom Bathgate
    Tom Bathgate  • 8 years ago

    This is so useful, and funnily enough I got the email update about it whilst looking for a solution. However I am having a problem. Having followed the steps above, when I submit a comment and ticked to subscribe i get the following error:

    Missing argument 2 for ymc_subscription_add() at line 23 of my functions which is:
    function ymc_subscription_add( $cid, $comment ) {

    Any ideas? i’m using wordpress 3.0.4

  28. Theo
    Theo  • 8 years ago

    Smart, really smart.Will try this one for sure, bookmarked and thanks!

  29. Nick Stamoulis
    Nick Stamoulis  • 8 years ago

    Great idea for a strategically placed call to action. After reading a well written and informative blog post people are more likely to click on something that is easily assessable like this, rather than go looking for a way to subscribe. Thanks for sharing.

  30. Vlad Rascanu
    Vlad Rascanu  • 8 years ago

    Try giving something for free. You’ll see your number of subscribers go through the roof if it’s a good quality giveaway of course; generally it’s an ebook, a crash course on something, etc.

  31. Jesse McFarlane
    Jesse McFarlane  • 8 years ago

    Another great idea Yoast–targeting people who have already “bought in” just makes sense.

  32. Bakkel
    Bakkel  • 8 years ago

    Who, sweet! Only I’m not able to code this one so I’ll wait when Joss has finished the plugin!

  33. Joss
    Joss  • 8 years ago

    I’m going to make this into a plugin I think. Will post here when it’s done!

    • Ronen Bekerman
      Ronen Bekerman  • 8 years ago

      Yoast, this is a great idea!

      Not sure how the conversion rate on this position compares to a subscribe section at the end of each post… I almost sure the attention and a user willing to subscribe is highest just as he finishes to read a good post before he goes to comment on it a little bit lower on the page.

      One thing is for sure – all those that appreciated the post and for some unearthly reason did not subscribe… might do so before they press submit on a comment they decided to place so this is a great catch-all type of thing!

      add to that the redirection to a thank you page with yet more options to let them follow you and you got a complete envelope for getting the most subscribers possible.



      I tried to code this myself… but that little end part on Yoast article about the check results and not overloading the API got me a little Jiggy about it.

      I’ll sure appreciate a plugin implementation of this.

      All the best


    • Bill Brikiatis
      Bill Brikiatis  • 8 years ago

      Joss — It would be great if you could make the plugin work for Feedburner. I don’t know if you would consider it?

    • Adam W. Warner
      Adam W. Warner  • 8 years ago

      If you do this Joss, I’m sure many people will instantly become your biggest fan…including me:)

  34. Barbu
    Barbu  • 8 years ago

    Woww, the way your site handles the first visitor’s comments is very good, I like it. To redirect visitors to a page and to aske them to confirm the email looks good (as long as you can add extrs information about the site on te rediretion page). Can I ask you what is the mechanism behind all of these?

  35. Barbu
    Barbu  • 8 years ago

    Cannot this be done with an existing plugin?

    • Joost de Valk

      Not that I know of and I have not currently got any plans to make a plugin out of it…

  36. Laura
    Laura  • 8 years ago

    I tried the above script but when I enter it all in my functions.php it gives me an error which makes make site unreachable. Or did I made the mistake that I should but it in my theme’s functions.php (instead of wordpress’ functions.php
    I would really really love to have a wordpress plugin for this!

    • Joost de Valk

      Your theme indeed.

      • Laura
        Laura  • 8 years ago

        Thanks for the quick reply. One more thing: do I leave the space after/before the ‘ at API key and List ID?

  37. Jason Lombard
    Jason Lombard  • 8 years ago

    Killer tip! I will be using this one for sure. Thanks!!!

  38. quicoto
    quicoto  • 8 years ago

    Ok so I’m using the Google’s Feedburner E-mail newsletter. And I don’t wanna switch to Mailchimp.

    1) Do you know if that’s posible with the Feedburner API?

    2) An other question… I guess I could do it manually by sending me an e-mail with the new suscriber.

    Should I sent it where you wrote “// DO WORK” ?



    • quicoto
      quicoto  • 8 years ago

      Thanks. I’ve been digging a little, I don’t think it’s posible.

      I’m going for the second option.


    • Joost de Valk

      1) Hey, you’ll have to get someone to figure that out for you :)

      2) yes.

  39. SilverMagpies
    SilverMagpies  • 8 years ago

    Yoast –

    Can you write a plugin to do this for those of us who should not be messing with code! Please :-)

    • Stephen Martin
      Stephen Martin  • 8 years ago

      I agree with this post. A Plugin for this would be great. Im sure Mailchimp would sponsor it if you spoke to them.

      • bhuthecoder
        bhuthecoder  • 8 years ago

        Plugin Done:
        Link: http://wordpress.org/extend/plugins/bhu-c2s/
        now trying to integrate awber.

        • Michael Aulia @CravingTech.com
          Michael Aulia @CravingTech.com  • 8 years ago

          This is why we all should check on a post comment first before doing or asking anything! :)

        • Adam W. Warner
          Adam W. Warner  • 8 years ago

          Whoo hoo! Thank you so much! I have installed and am testing now.

Check out our must read articles about WordPress