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:
You can fetch all providers that support follower counts. This will return a collection of Provider objects.
{% for provider in craft.socialShare.getFollowerCountProviders() %}
{{ provider.name }}
{% endfor %}
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, you can use the guide below for what value the second parameter needs to be:
craftcms
)craftcms
)@craftcms
)Lofigirl-Chillbeats
)You can pass in a number of options to control output.
{{ craft.socialShare.getFollowers('facebook', 'craftcms', {
enableCache: true,
cacheDuration: 3600,
friendlyCount: false,
}) }}
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