Disable Shared Counts on certain categories

The Shared Counts plugin lets you specify where in a post the share buttons appear (before and/or after content). You can also exclude them on a specific post using the metabox when editing that post.

For even more control, you can use the locations filter to move or remove the share buttons programmatically. The code below removes the share buttons from any post in the “sponsored” category.

 * Remove Shared Counts from sponsored posts 
 * @link https://www.billerickson.net/code/disable-shared-counts-on-certain-categories/
 * @author Bill Erickson
function be_remove_shared_counts_from_sponsored_posts( $locations ) {
  if( is_single() && has_category( 'sponsored' ) ) {
    $locations['before']['hook'] = false;
    $locations['before']['filter'] = false;
    $locations['after']['hook'] = false;
    $locations['after']['filter'] = false;
  return $locations;
add_filter( 'shared_counts_theme_locations', 'be_remove_shared_counts_from_sponsored_posts' );

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