Display different buttons in each location

In Settings > Shared Counts you can control the site-wide settings for which share buttons are shown and where they appear (before and/or after content).

For more fine grained control, you can use the shared_counts_display_services filter (added in version 1.3) to customize which services are available in each location. You might also be interested in our tutorial on changing button style by location.

If you want only Facebook, Pinterest, and Email to appear before the post content, use:

This code snippet goes in a core functionality plugin or Code Snippets.

/**
 * Shared Counts - change buttons in "Before Content" location
 * @see https://sharedcountsplugin.com/2019/03/27/display-different-buttons-in-each-location/
 */
function be_shared_counts_before_content_buttons( $services, $location ) {
	if( 'before_content' === $location )
		$services = array( 'facebook', 'pinterest', 'email' );
	return $services;
}
add_filter( 'shared_counts_display_services', 'be_shared_counts_before_content_buttons', 10, 2 );Code language: PHP (php)

This also works when you create custom locations in your theme or plugin. The code below displays the Facebook, Pinterest, and Email services in the “sharing_cta” location (a custom call to action in our theme):

/**
 * Shared Counts - change buttons in "Before Content" location
 * @see https://sharedcountsplugin.com/2019/03/27/display-different-buttons-in-each-location/
 */
function be_shared_counts_before_content_buttons( $services, $location ) {
	if( 'sharing_cta' === $location )
		$services = array( 'facebook', 'pinterest', 'email' );
	return $services;
}
add_filter( 'shared_counts_display_services', 'be_shared_counts_before_content_buttons', 10, 2 );Code language: PHP (php)

Filters used:

Published by Bill Erickson

Bill Erickson is a freelance WordPress developer and a contributor to the Genesis framework. For the past 14 years he has worked with attorneys, publishers, corporations, and non-profits, building custom websites tailored to their needs and goals.