Testing some fediversal URL auto embeds for WordPress happening in this here blog, now with slapping a naked URL on its own line:

https://cosocial.ca/@cogdog/115613213272065972

which embeds beautifully just like this- SHAZAM!~

Alan is @cogdog

For the Love of Carnegie Libraries carnegielibraries.org/

November 26, 2025, 12:40 am 0 boosts 0 favorites

Can we go beyond mastodon? What about a pixelfed URL?

https://pixelfed.social/p/cogdog/873949556324687103

and yup. I am seeing an embedded pixelfed photo here. WINNING!

As it turns out I have been wrong about how this is working. I had been using some code I have stuffed in a Cogdog Auto Embed Extras WordPress Plugin I have for a variety of extra auto embeds, used elsewhere in SPLOTbox theme. Typically these are set up because the URL patterns are pretty easy to match, but with fedistuff, the domains are not known in advance,

The relevant code for Mastodon and Pixelfeed is a regex search that looks for URLs like:

https://any.instance.blah/@[username_string]/string_of_digits0-9/

It seems to match all fediverse URLs, I guess it could barf on something else. For the maybe one reader who might follow along,these are set up be registering the embed patterns.

add_action( 'init', 'cdb_register_embeds' );

function cdb_register_embeds() {
	// handler for mastodon		
	wp_embed_register_handler(
		'mastodon',
		'#^https?:\/\/((?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9])\/@([a-zA-Z0-9\_]+)\/(\d+)$#i',
		'cdb_handler_mastodon'
	);
	
	
	// handler for pixelfed
	wp_embed_register_handler(
		'pixelfed',
		'#^https?:\/\/((?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9])\/p\/[a-zA-Z0-9\_]+\/(\d+)$#i',
		'cdb_handler_pixelfed'
	);

}

And these each reference a function called to embed them as iframes:

function cdb_handler_mastodon( $matches, $attr, $url, $rawattr ) {
	// handler for mastodon embeds
	$embed = '<iframe src="https://' . esc_attr($matches[1]) . '/@' . esc_attr($matches[2]) . '/' . esc_attr($matches[3]) . '/embed" class="mastodon-embed" style="max-width: 100%; border: 0" width="800" allowfullscreen="allowfullscreen"></iframe><script src="https://' . esc_attr($matches[1]) . '/embed.js" async="async"></script>';

	return $embed;
}

function cdb_handler_pixelfed( $matches, $attr, $url, $rawattr ) {
	// handler for pixelfed embeds
	$embed = '<iframe src="' . esc_attr($matches[0]) .  '/embed?caption=false&likes=false&layout=compact" class="pixelfed__embed" style="max-width:100%; min-height:600px; border:0" width="600" allowfullscreen="allowfullscreen"></iframe><script async defer src="https:/' . esc_attr($matches[1]) . '/embed.js" async="async"></script>';

	return $embed;
}

But then, while testing the ActivityPub setup I had toyed with on WordPress.com when it first came out. In writing that post, I could see WordPress was autoembedding a Mastodon URL — how was it doing that?

First I commented out my crufty duct tape code above, and redid the two embeds at the top of the post- the pixelfed one is much better than what I had before.

So I started testing on a few other websites and discovered:

  • I do not get fediverse autoembeds on many sites (It renders the naked URL)
  • It does work only on sites with the ActivtyPub plugin enabled, I get a embed,

What to do? I download the ActivityPub plugin, poke around the include directory, and find a file class-embed.php which indicates at the top:

<?php
/**
 * ActivityPub Embed Handler.
 *
 * @package Activitypub
 */

namespace Activitypub;

/**
 * Class to handle embedding ActivityPub content.
 */
class Embed {

:
:

I am not sure I understand everything, but I am sure that enabling the ActivtyPub plugin on a WordPress sites gives as a bonus the autoembeds of fediverse URLs. I can’t find this mentioned anywhere I have looked so far.

With this I live up to the spirit of my pinned Mastodon post, which I can embed with just pasting its URL in here every so seriously:

Alan is @cogdog

@tdc Voltaire had an unsaid but well known life summary. I take mine seriously, inevitable SERIOUSNESS .

A joyful dog is running towards the viewer, blue ball in mouth, ears flapping like wings, all four paws off the ground. Text on the right reads "@cogdog was perfunctorily and professionally serious in his endeavors" This is 10000% sarcasm.
January 23, 2024, 9:36 pm 1 boosts 10 favorites

Expect a lot more of these!


Featured Image: 2013/365/52 The Potter Box flickr photo by cogdogblog shared under a Creative Commons (BY 2.0) license A mystery box of electronics sent to me by Grant Potter — hey man, it still works!

A small wood box with dials and swithes on the frpont, sitting on top are two hub shaped mysterious objects with cables. What does this box do?
If this kind of stuff has value, please support me by tossing a one time PayPal kibble or monthly on Patreon
Become a patron at Patreon!
Profile Picture for CogDog The Blog
An early 90s builder of web stuff and blogging Alan Levine barks at CogDogBlog.com on web storytelling (#ds106 #4life), photography, bending WordPress, and serendipity in the infinite internet river. He thinks it's weird to write about himself in the third person. And he is 100% into the Fediverse (or tells himself so) Tooting as @cogdog@cosocial.ca

Comments

  1. @barking From down in the WordPress weeds- I do not know if this feature is listed anywhere, but I discovered that if you activate the WordPress @activitypub.blog plugin, as a bonius your blog is now equipped to autoembed URLs from at least Mastodon and Pixelfed.

    Amirite @pfefferle ??

Leave a Reply

Your email address will not be published. Required fields are marked *