Why
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.
What
Find out how webmentions are stored, and how they are presented. Change the presentation by displaying an excerpt.
How
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
- changed the character count limit to 500
// Mentions with content less than this length will be rendered inline.
define( 'MAX_INLINE_MENTION_LENGTH', 500 );
- 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. - 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);
- After it sets the length of the webmention, stored in
Mentions
Likes