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

Tag in post #2

Closed b4zz4 closed 4 years ago

b4zz4 commented 4 years ago

This plugon take the tags of the publication and add it to the publication of mastodon

janboddez commented 4 years ago

If you wanted to automatically append tags (as hashtags) to a Mastodon status, you could do that as follows (add to your theme's functions.php):

add_filter( 'share_on_mastodon_status', function( $status, $post ) {
  $tags = get_the_tags( $post->ID );

  if ( $tags ) {
    $status .= PHP_EOL . PHP_EOL;

    foreach ( $tags as $tag ) {
      $status .= '#' . preg_replace( '/\s/', '', $tag->name ) . ' ';
    }

    $status = trim( $status );
  }

  return $status;
}, 10, 2 );

I might include something similar in the next version of the plugin.

b4zz4 commented 4 years ago

Very good :D