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 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