How to add a Mastodon verified link without a plugin

You can add Mastodon verified links to your WordPress site without using a plugin by adding a code snippet (below).

If you’re not sure what a verified link is, they look like this, with the check:

A screenshot of the list of links on my Mastodon profile, showing one of the links as verified with a checkmark.

First make sure to use the core Mastodon social link block and add a link to your Mastodon profile:

Screenshot of the WodrPress block editor UI, showing a Mastodon social link added to the page, with the URL editor opened.

Then add the following code snippet to your child theme’s functions.php:

// Filter the Mastadon social link and add rel=me
function add_mastodon_rel_me( $block_content, $block ) {

	if ( $block['attrs']['service'] !== 'mastodon' ) {
		return $block_content;
	}

	$block_content = preg_replace( '@<a(.*)>@U', '<a$1 rel="me">', $block_content );
	return $block_content;
}

add_filter( 'render_block_core/social-link', 'add_mastodon_rel_me', 10, 2 );

I’m using this for the link at the bottom of this site ⬇

Disclaimer: all Mastodon links (via the social link block) will be updated with the rel=”me” attribute – probably fine for personal sites but maybe not if you are using multiple Mastodon profile links.

Update: I’ve been kindly informed that with Gutenberg 14.5 the link block comes with a rel attribute option in the UI, this is not yet released in core (my guess would be WP 6.2) but you can get it today by installing the Gutenberg feature plugin.


Posted

in

,

by

Tags: