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

Add specific tags to Mastodon status #34

Closed davemreed closed 1 year ago

davemreed commented 1 year ago

Hi Jan,

I'm using this code in our functions file, based on your examples:

// Post Excerpt with link add_filter( 'share_on_mastodon_status', function( $status, $post ) { $status = wp_strip_all_tags( $post->post_excerpt ); $status .= "\n\n" . get_permalink( $post ); return $status; }, 10, 2 );

It's working exactly as expected. I would like to add two specific tags that will be added with every status post, with a line break after the URL. Like this:

Text

Link

Tags

I can't quite figure this out. Could you point me in the right direction?

janboddez commented 1 year ago

You mean like not the post's tags but two "hardcoded" hashtags?

You could probably do the same as before, but slightly modified:

// Post Excerpt with link
add_filter( 'share_on_mastodon_status', function( $status, $post ) {
  $status  = wp_strip_all_tags( $post->post_excerpt );
  $status .= "\n\n" . get_permalink( $post );
  $status .= "\n\n" . '#TagOne #TagTwo';

  return $status;
}, 10, 2 );
davemreed commented 1 year ago

Perfect! Exactly what we needed. Thanks for the great plugin!