Nomention

There was a recent scenario where I linked to a conversation on micro.blog but, as well as my post being fed through as normal, the generated webmention was interpreted as a reply meaning the full post content showed as a separate response in the conversation.

Micro.blog doesn't make the distinction between webmention types so I wondered about editing the webmention plugin for WordPress by adding class="nomention" or rel="nomention" to a link so that it isn't processed along similar lines to rel="nofollow".

Unknown to me at the time, Chris Aldrich had also recently proposed rel="nomention" but I personally prefer using class as I can easily add this in Drafts using multi-markdown which is supported by WordPress via JetPack:

[Link text](http://link.here) {.nomention}

Matthias Pfefferle (the plugin author) suggested building a blacklist feature so named domains could be excluded but I wouldn't necessarily want this to be the case, having it more at the individual link level so as not to completely preclude sending webmentions to particular sites.

The webmention plugin for WordPress uses the function wp_extract_urls() to grab all links from the post content so I thought about replacing this, finding all link tags instead then, for each that doesn't include nomention, get the url. The initial code looks like this:

preg_match_all('/<a[^>]+>/i',$post->post_content, $results); 

$mentions = '';
foreach ($results[0] as $link) {
  if (strpos($link, 'nomention')) {
    $mentions .= $link;
  }
}

$links = wp_extract_urls($mentions);

It may be preferable to check the full class="nomention" just in case the url includes “nomention” - you never know.

While this works, as pointed out, there are some issues with it in its current form. Firstly, it only deals with <a> tags so ignores images, videos, etc. but it could be extended for multiple tags:

(<a[^>]+>|<img[^>]+>|...)

A more pressing issue, however, is that most people do not, and will not, manually edit the HTML in their posts, especially with the release of the WordPress Gutenberg editor on the horizon. As such, the application of the relevant flag would need to be via an option in the UI. This could be easily achieved at the post level (a "do not send webmentions for this post" checkbox) but not so at the link level.

The question also arises as to whether something like micro.blog should better handle webmention types rather than automatically making everything a reply. As Chris suggests, however, there could be other scenarios where not sending a webmention is preferred.

This is likely an extreme edge case (at least I'm not the only one who's considered it) but I thought it worth discussion even if dismissed.

The implementation works for me and my posting workflow so I'll keep it, even though it will mean manually editing the plugin each time it is updated.

Leave a Reply

Your email address will not be published.