Feature Tour

Follower Counts

Similar to Share Counts, you can also fetch the number of followers or subscribers a particular user has on a social media platform. For example, we can query how many subscribers a YouTube channel has, or how many people follow you on Pinterest.

Follower counts are heavily cached to prevent slow page loading, and triggering API's. This is controlled with the cacheDuration plugin setting.

The following providers support fetching follower counts:

ProviderRequirements
DribbbleConfigure and connect the provider under Settings → Social Share → Providers.
EnvatoConfigure a personal token.
FacebookNo account configuration is required.
FeedlyNo account configuration is required.
GitHubNo account configuration is required.
InstagramConfigure and connect the provider under Settings → Social Share → Providers.
MailchimpConfigure an API key.
MixCloudNo account configuration is required.
PinterestNo account configuration is required.
SoundCloudNo account configuration is required.
SteamNo account configuration is required.
VkontakteNo account configuration is required.
X (Twitter)Configure the provider with your Client ID and Client Secret.
YouTubePass an @handle or a channel ID beginning with UC.

Provider credentials are configured under Settings → Social Share → Providers. Environment variables keep credential values out of project config.

Getting Follower Count Providers

You can fetch all providers that support follower counts. This will return a collection of Provider objects.

{% for provider in craft.socialShare.getFollowersCountProviders() %}
    {{ provider.name }}
{% endfor %}

Getting Follower Counts

You'll also want to fetch the counts for the social media platform. You can do so by calling getFollowers() for the provider you want to check against. You'll also need to provide the username, channel or other identifier for the platform. Let's fetch follower counts for a user on Facebook.

{{ craft.socialShare.getFollowers('facebook', 'craftcms') }}

This should return the total number of followers for craftcms (e.g. 2K).

As each platform is different, use the guide below for the value passed as the second parameter:

  • Facebook — page ID or username, such as craftcms.
  • Pinterest — username, such as craftcms.
  • YouTube — handle, such as @craftcms, or channel ID, such as UC45X_OuS3I2Kq7ILkS5A1uw.

Dribbble and Instagram return the follower count for the connected account. Their account argument is still required for call compatibility, but its value does not select another account.

Render Options

You can pass in a number of options to control output.

{{ craft.socialShare.getFollowers('facebook', 'craftcms', {
    enableCache: true,
    cacheDuration: 3600,
    friendlyCount: false,
}) }}

Friendly Numbers

By default, Social Share will convert the raw number (e.g. 54624) to a "friendlier" abbreviated notation like 54.6K. You can control this via the friendlyCount plugin setting, or by passing this in as an option when rendering.

{{ craft.socialShare.getFollowers('facebook', 'craftcms', {
    friendlyCount: false,
}) }}

{# Would render... #}
87372