Function – dslc_get_social_count()

Function dslc_get_social_count() can be used to get the amount of shares the current post/page has on twitter, facebook and pinterest. It returns an array with keys “fb”, “twitter”, “pinterest”.

It accepts 2 parameters, first is the post ID ( in case you want to get social shares of a specific post/page instead of the current one ) and the second one is cache time in milliseconds ( how long until it should recheck again for the shares count, defaults to 3600 seconds, which is of course 1 hour ).

	$share_info = dslc_get_social_count();
<span class="share-count">Facebook: <?php if ( $share_info ) { echo esc_html( $share_info['fb'] ); } ?></span>
<span class="share-count">Twitter: <?php if ( $share_info ) { echo esc_html( $share_info['twitter'] ); } ?></span>
<span class="share-count">Pinterest: <?php if ( $share_info ) { echo esc_html( $share_info['pinterest'] ); } ?></span>