Skip to content

Instantly share code, notes, and snippets.

@gwire
Last active November 21, 2022 10:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gwire/d4197e75f6be1336612d4ff97b85e80d to your computer and use it in GitHub Desktop.
Save gwire/d4197e75f6be1336612d4ff97b85e80d to your computer and use it in GitHub Desktop.
Adding rel="me" to WordPress social link block items
<?php
/**
* Mastodon accounts can be verified by adding a rel="me" link in the basic rendered html.
* While a <link/> could be added, it seemed like the existing social-links block should be
* the place to add it, but there's currently no way to specify "rel" values in the UI.
*
* Currently only adds to "mastodon" links, but could probably be added to others.
*/
add_filter('render_block', 'social_rel_me', 10, 2);
function social_rel_me($block_content, $block) {
if ( $block['blockName'] === 'core/social-link' ) {
if ( $block['attrs']['service'] === 'mastodon' ) {
$block_content = preg_replace('/<a /', '<a rel="me" ', $block_content);
}
}
return $block_content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment