Skip to content

“Tootstorms” using Micropub and Share on Mastodon

I mostly use Indigenous, on Android, and Micropub to post “Tweetstorm-like” status threads to this blog. Like, I’ll post a note, navigate to it, post a reply, and so on.

These replies also automatically get a link to the previous, or parent, note added in front of them. There’s several benefits to this: (1) less typing for me, (2) clear RSS feeds—followers are able to interpret replies as being in reply to some other URL—and (3) Webmention.

There’s a fourth benefit, though: I can not just crosspost complete notes and replies to my Mastodon account like I always do, but create entire Mastodon threads, where replies are displayed right underneath their parent statuses, as well.

This trick requires two steps. The first’s determining which “Mastodon” status we’re really replying to, and involves some regex magic to convert the automatically added u-in-reply-to URL to the ID of its corresponding toot, and looks sort of like this:

$pattern = '#<a(?:.+?)href="' . home_url( '/notes/' ) . '(.+?)"(?:.*?)>(?:.+?)</a>#';

if ( preg_match( $pattern, $status, $matches ) ) {
  // Status contains a link to a note of our own. Try to fetch that note.
  // `iwcpt_note` is the Custom Post Type I use for notes.
  $post_parent = get_page_by_path( rtrim( $matches[1], '/' ), OBJECT, array( 'iwcpt_note' ) );

  if ( $post_parent ) {
    $toot_id = basename( get_post_meta( $post_parent->ID, '_share_on_mastodon_url', true ) );

Essentially, this’ll look for the first link, if any, to a note on my blog—this would be the note I’m replying to—and try to fetch the ID of its Mastodon counterpart.

The second part is adding this toot ID to the arguments I’m passing to Mastodon’s API:

if ( ! empty( $toot_id ) ) {
  // Add to existing thread.
  $args['in_reply_to_id'] = $toot_id;

Now, where would all of this code go? Simple: in a callback to the share_on_mastodon_toot_args filter hook.

Note: I obviously do just a tiny bit more, like, I’ll actually drop the “In reply to …” text from the syndicated copy, and so on, so as not to bother my Mastodon followers with too much redundant information.


  1. Jan Boddez on

    Should probably add that the Micropub part is super convenient, but entirely optional.

    Via, in reply to “Tootstorms” using Micropub and Share on Mastodon.