Skip to content

Instantly share code, notes, and snippets.

@Nahuai
Last active November 16, 2023 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nahuai/82502783f75044ff361d51001aa8d409 to your computer and use it in GitHub Desktop.
Save Nahuai/82502783f75044ff361d51001aa8d409 to your computer and use it in GitHub Desktop.
Filter social icons block URL
add_filter( 'render_block_data', 'cg_add_url_social_block' );
function cg_add_url_social_block( $parsed_block ) {
$wordpress = get_the_author_meta( 'wordpress' );
$github = get_the_author_meta( 'github' );
$twitter = get_the_author_meta( 'twitter' );
$mastodon_url = get_the_author_meta( 'mastodon_url' );
if ( 'twitter' === $parsed_block['attrs']['service'] && 'core/social-link' === $parsed_block['blockName'] ) {
$parsed_block['attrs']['url'] = 'https://twitter.com/' . $twitter . '';
}
if ( 'wordpress' === $parsed_block['attrs']['service'] && 'core/social-link' === $parsed_block['blockName'] ) {
$parsed_block['attrs']['url'] = 'https://profiles.wordpress.org/' . $wordpress . '';
}
if ( 'github' === $parsed_block['attrs']['service'] && 'core/social-link' === $parsed_block['blockName'] ) {
$parsed_block['attrs']['url'] = 'https://github.com/' . $github . '';
}
if ( 'mastodon' === $parsed_block['attrs']['service'] && 'core/social-link' === $parsed_block['blockName'] ) {
$parsed_block['attrs']['url'] = '' . $mastodon_url . '';
$parsed_block['attrs']['rel'] = 'me';
}
return $parsed_block;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment