Show total share count for “included total” field

The “Included Total” field in Shared Counts displays the sum total of counts across all the other buttons you’re displaying. It does not use the “total” value you see when editing a post. For instance, if you don’t include a Pinterest button on your site, it won’t include your Pinterest pins in the count total.

The code below changes the “Included Total” field to show the total across all services, regardless of whether you’re including a button. This is best used if you are only showing the total count ( you have “Count Total Only” checked in Settings > Shared Counts).

/**
 * Show total share count for included total
 *
 * @author Bill Erickson
 * @link https://www.billerickson.net/code/total-share-count
 *
 * @param array $link
 * @param int $id
 * @param string $style
 * @return array $link
 */
function be_shared_counts_total( $link, $id, $style ) {
	if( 'included_total' == $link['type'] ) {
		$link['count'] = shared_counts()->core->count( $id, 'total' );
	}

	return $link;
}
add_filter( 'shared_counts_link', 'be_shared_counts_total', 5, 3 );

Bill Erickson

Bill Erickson is the co-founder and lead developer at CultivateWP, a WordPress agency focusing on high performance sites for web publishers.

About Me
Ready to upgrade your website?

I build custom WordPress websites that look great and are easy to manage.

Let's Talk