Webmentions are a simple way to send and receive notifications that a URL has been mentioned elsewhere on the web.
They supersede pingbacks, having begun as a simpler version, and now have the support of a W3C recommendation for a web standard.
Why is this of interest? Well, Micro.blog will be using webmentions to notify you of replies or likes to your posts when self-hosted.
Fortunately, for WordPress users, there is a readymade plugin that provides support for both sending and receiving webmentions.
The plugin registers ‘webmention’ as a custom comment type making it extremely simple to display mentions using the normal WordPress methods.
When tweaking my theme I deliberately removed everything related to comments as I wanted it to be as minimal as possible. I also wanted replies to my posts to be left on Medium.
Now, while the blog was able to receive the webmentions (and these would appear as comments in the site backend) the removal of all comment functionality meant that these notifications could not be displayed on the site.
Queue Operation Rebuild!
The solution? Recreate a comment section but only to display webmentions for the microblog.
Without a comment form, and with such a limited scope, this was remarkably easy to achieve with very little code.
The following was added to single.php (the WordPress template for an individual post) to only show a comment section if viewing a microblog post with comments:
<?php if ( in_category('microblog') && get_comments_number() ) : comments_template(); endif; ?>
Because no other logic is required, all the comment template (comments.php) needs to display is webmentions:
<div id="comments" class="comments-area"> <h5 class="comments-title"> Reactions </h5> <ol class="comment-list"> <?php wp_list_comments( 'type=webmention' ); ?> </ol> </div>
One simple command surrounded by some HTML for display and formatting purposes.
It’s not a perfect solution as a microblog post could potentially have another type of comment, a pingback for example, but the only issue would be that the “Reactions” header might be shown when there are no webmentions.
I could solve this with a separate function if it becomes a problem but I don’t envisage getting other comments on the microblog posts.
I decided to look for a solution to the potential issue above and found this function which can be used to check for a specific comment type on the current post – seems to work nicely.
Leave a reply on Medium.