How to switch off social sharing for a specific category

Posted in: Newspaper
Post count: 14

Hi, I am setting up a membership site and need to use posts rather than pages to be able to gather them into categories. I have gone into the theme panel to turn off the social sharing for the relevant category but the settings are either on or off – no selection of categories.

I do not want to turn sharing off completely as it will affect my public site. How can I switch sharing off for specific categories?

Thanks

Post count: 22421

Hello,

Our theme does not have this option to remove the sharing widget on specific posts so it will have to be made custom .luckily it;s not very hard to do it. you can use this function: https://developer.wordpress.org/reference/functions/in_category/ This will check if the post belongs to a specific category. Then you can add a condition to the social widget like so: http://screencast.com/t/jjiJbOcjZg You will have to do this for every post style that you use. Further down the file shown is the social sharing bottom code you can also place inside such a condition.

<?php if (in_category('gadgets')){
         echo $td_mod_single->get_social_sharing_top();
} ?>

This will result the sharing to only be enabled for the gadgets category. The reverse is !in_category like so:

<?php if (!in_category('gadgets')){
         echo $td_mod_single->get_social_sharing_top();
} ?>

I hope this helps.
Thanks

Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic.