How to Show Your MailChimp Subscriber Count on WordPress

WordPress

One reason you may want to show a subscriber count on your WordPress installation is if you actually have a high number of subscribers. If a few thousand people have subscribed to your list, this is social proof that can encourage others to sign up.

If you use MailChimp, there are two methods to show your subscriber count on WordPress. We’re going to introduce you to both of them.

Using the Chiclet Plugin

The first way to do this is to simply install the MailChimp Subscriber Chiclet plugin. Once you’ve activated it, visit the settings page and you can begin configuring the plugin.

The first step is to enter your MailChimp API key. You can find this on the account dashboard on the MailChimp site itself. Save the changes you make and then your plugin will load the list from your MailChimp account. Select the list and begin configuring the settings according to your needs.

Once you’re ready to go, copy the shortcode, found at the bottom of the plugin, and add it to any area where you want to show the number of subscribers you have.

We recommend utilising this option as it’s generally the simplest, but there is another way.

Showing Subscriber Count via the API

One of the reasons you may opt for this method is you can eliminate the ‘Powered by MailChimp’ logo normally displayed at the bottom where the subscriber account is. By using just the number, you can combine it with customised email forms.

This method is more complex because we’ll be creating a plugin from scratch.

Guide to Creating the Plugin

Step 1 – Create a desktop folder named ‘mc-subscriber-count’.

Step 2 – Create a new file within the folder named ‘mc-subscriber-count.php and paste the following code inside:

<?php
/*

Plugin Name: MailChimp Subscriber Count

Plugin URI: http://www.wpbeginner.com

Description: Retrieves MailChimp subscriber count and displays it as a text

Version:     1.0

Author:     WPBeginner

Author URI: http://www.wpbeginner.com

*/

function wpb_mc_sub_count() {

include "Mailchimp.php";

$lastRunLog = 'logs/lastrun.log';

$subfile = 'logs/subcount.log';

$lastRun = file_get_contents($lastRunLog);

if (time() - $lastRun >= 86400) {

$MailChimp = new MailChimp('Your_MailChimp_API_Key');

$mc = $MailChimp->call('lists/list');

$subscriber_count .= $mc[data][0][stats][member_count];

file_put_contents($lastRunLog, time());

file_put_contents($subfile, $subscriber_count);

} else {

$subscriber_count .= file_get_contents($subfile);

}

return number_format($subscriber_count);

}

add_shortcode('mc-subscribers', 'wpb_mc_sub_count');

add_filter('widget_text', 'do_shortcode');

?>

You should add your own MailChimp API key where it reads ‘Your MailChimp API Key’.

Step 3 – Create another folder and name it ‘logs’. Within the ‘logs’ folder you should have two empty files using Notepad. Name these ‘subcount log’ and ‘lastrun log’.

Step 4 – Go to the MailChimp repository and download the source code for the MailChimp PHP Wrapper. Copy and paste the MailChimp folder and php file to the special plugin folder we just created.

Step 5 – Upload these files using an FTP transfer programme and activate your new plugin. By using the short code, you can have the subscriber count appear anywhere you like.

Last Word

If you have no experience with working with plugins, you may find it easier to use the first method. Nevertheless, this is a simple process and anyone with a basic knowledge of WordPress should have no problem following this step-by-step guide.

Share it!Share on FacebookTweet about this on TwitterShare on Google+Email this to someone

Our Recommended Wordpress Web Hosting Provider

WordPress

WHC.CA
Get a 50% Discount by using our link.

WHC.ca

Reliable host, with excellent customer service and an easy one-click Wordpress installation. Our recommendation to host a Wordpress blog.

Leave a Reply

Your email address will not be published. Required fields are marked *