POSSE WP->Mastodon

I wish that it were possible to leverage WordPress’ post formats (status, aside, etc.) to trigger crossposting. In the absence of that functionality I’m working with Jan’s excellent WordPress to Mastodon plugin, making a couple of minor mods:

  • If it’s a short (status, under 400 chars) WordPress post, just send the post content to Mastodon with no title or link back to the original wordpress post. If it’s a longer entry, post an excerpt and link back to WordPress.
  • Add tags to the Mastodon post with #’s.

Here’s the code I’m using:

add_filter( 'share_on_mastodon_status', function( $status, $post ) {
    // Check if the length of the post content is more than 400 characters
    if (strlen($post->post_content) > 400) {
        // Use the post excerpt if content is longer than 400 characters
        $excerpt = get_the_excerpt($post);
        // Replace HTML entity with "read more..." text and permalink
        $read_more_link = '... read more: ' . get_permalink($post);
        $excerpt = str_replace('…', $read_more_link, $excerpt);
        $status = wp_strip_all_tags($excerpt, '<a>');
    } else {
        // Use the full post content if it's 400 characters or less
        $status = wp_strip_all_tags($post->post_content);
    }
    
	
  $tags = get_the_tags( $post->ID );

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

    $status = trim( $status );
  }
    return $status;
}, 10, 2 );

I’m going to sit with this for a while. I think the route I’m ultimately going to take though is just modify this plugin to only crosspost to Mastodon entries that have the category of “status” assigned to them. Not sure yet. Will give this a while to settle.

Posted

in

Current Spins

Top Albums

Check out my album Set It All Down on your favorite streaming service.


Posts Worth Reading:


Letterboxd


Reading Notes

  • Who profits from our constant state of dissatisfaction? The answer, of course, is painfully obvious. Every industry that sells a solution to a problem you […]
  • the shifts have been in place for awhile. A certain kind of book—say those reviewed in the NYRB—will become like opera, or theater, or ballet, […]
  • • No more struggle: “Whatever arises, train again and again in seeing it for what it is. The innermost essence of mind is without bias. […]
  • The real problem, in my mind, isn’t in the nature of this particular Venture-Capital operation. Because the whole raison-d’etre of Venture Capital is to make […]
  • . The EU invokes a mechanism called the precautionary principle in cases where an innovation, such as GMOs, has not yet been sufficiently researched for […]

Saved Links