janboddez / share-on-mastodon

Easily share WordPress posts on Mastodon.
https://jan.boddez.net/wordpress/share-on-mastodon
GNU General Public License v3.0
39 stars 5 forks source link

Excluding categories #31

Closed davemreed closed 2 years ago

davemreed commented 2 years ago

Thanks for your work on this plugin. Is it possible to exclude specified categories from posting to Mastodon?

janboddez commented 2 years ago

It is (or should be)! If you're familiar with modding WordPress sites through your theme's functions.php or a (mu-)plugin, here's one way of doing so:

add_filter( 'share_on_mastodon_enabled', function( $is_enabled, $post_id ) {
  if ( has_category( 'my-category-slug', $post_id ) ) {
    // Do not share posts in `my-category-slug`.
    return false;
  }

  return $is_enabled;
}, 10, 2 );

As per the example on https://jan.boddez.net/wordpress/share-on-mastodon#share_on_mastodon_enabled

davemreed commented 2 years ago

I read that page and totally spaced over that example, thanks!