Skip to content

Adding Some Context to (Web)mentions

Triggered by Ton’s “Webmention tweaks”—or is it “Semantic Linkbacks tweaks”?—I decided to have a look at how WordPress generates its increasingly rare pingback “previews.”

The resulting gist is a somewhat ugly PHP function that, given an HTML string and target URL, returns the link text, plus some of the text surrounding it. (Moreover, this excerpt—or “context”—is restricted to the block-level element containing the link.) That is, if a link to the target URL is present. (An empty string is returned otherwise.)

The code’s pretty much lifted from WordPress core and eventually strips all HTML tags, so it should be safe to reuse. (In fact, it may need to be modified a bit, to explicitly keep some HTML, just like “normal” WordPress comments.) And, because selfdogfood, I’m using it on this site, too.

It may even be possible to hook into one of Semantic Linkbacks’ filters, something I did previously look into as well, and then sort of forgot about—I myself don’t use the plugin.


  1. on

    … bookmarked this!

    Via, in reply to Adding Some Context to (Web)mentions.

  2. Jan Boddez on

    […] here’s a rather random note linking to two posts on my […]

    Via, in reply to Adding Some Context to (Web)mentions.