Manually Display Shared Counts

You can call the display method within your theme or plugin file to include the share buttons. The “function exists” part ensures this code only runs if Shared Counts is active.

if( function_exists( 'shared_counts' ) {
	shared_counts()->front->display();
}

You can also pass the following parameters to the display method:

  1. Location (adds a CSS class to the shared-counts-wrap so you can apply location-specific styling)
  2. Echo, whether you want it to echo or return the markup
  3. Style, specify a button style for this location, overriding the site-wide default style
  4. Post ID, specify a post ID different than the current post (ex: for a custom loop)

For instance, if you wanted to add a “sidebar-top” location that uses the icon style (different from the style you specified in Settings > Shared Counts) you can use this:

if( function_exists( 'shared_counts' ) {
	shared_counts()->front->display( $location = 'sidebar-top', $echo = true, $style = 'icon' );
}

See the source code for more information.

Bill Erickson

Bill Erickson is a freelance WordPress developer and a contributing developer 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.

Ready to upgrade your website?

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

Let's Talk