Webmention tweaks



Webmentions were shown as “Peter mentioned this on ruk.ca”, but that does not provide context for a reader to decide if they want to click to go there. So I want to display a part of the linked item, as a teaser. Years ago pingbacks were presented like that on my site.


Find out how webmentions are stored, and how they are presented. Change the presentation by displaying an excerpt.


It turned out that webmentions are actually stored in full (so the text of the linked item is available in my wordpress database). It was just that the template for how it got presented needed tweaking. There is also a character count limit, below which a mention is indeed shown as I like it. All this however isn’t done in the theme, but in a plugin, called Semantic Linkbacks and in a specific file: class-linkbacks-handler.php. Once I localised that, I could change what I needed.
So I

  1. changed the character count limit to 500
    // Mentions with content less than this length will be rendered inline.
    define( 'MAX_INLINE_MENTION_LENGTH', 500 );
  2. changed the template for a webmention in public static function get_comment_type_excerpts()
    It was 'mention'=> __( '%1$s mentioned %2$s on href="%3$s">%4$s., 'semantic-linkbacks' )
    I changed it to
    'mention'=> __( '%1$s mentioned %2$s on href="%3$s">%4$s: %5$s', 'semantic-linkbacks' )
    This adds a 5th parameter at the end. This will hold the excerpt.
  3. Then filled that template in, in function public static function comment_text_excerpt
    • After it sets the length of the webmention, stored in $text in $text_len I evaluated that to see if it is longer then the limit. If so it sets a delimiter $text_delim to that maximum, or else sets it to the actual length.
    • Then I create a text snippet from the start of the text to that delimiter $text_snip = substr($text, 0, $text_delim) and add a few dots to the end $text_snip .=" ...."
    • That snippet is then added as 5th parameter to a call of the template mentioned above $text = sprintf( $comment_type_excerpts[ $semantic_linkbacks_type ], get_comment_author_link( $comment->comment_ID ), $post_type, $url, $host, $text_snip);


  • This tweak is to a plugin, so the next update will overwrite my changes. Need to figure out how to post it back to the plugin source so it might get incorporated as an option
  • Still need to change how the excerpt is selected. Now it is some 500 characters from the start of a posting. I want it to be 500 characters around the actual link.
  • It seems I need to change webmentions for various types, as a reply to a comment I made is shown as ‘x mentioned y’ (I changed it to the text of the actual comment by hand in this case.)