Site logo

Archived topic

rel="me" for socialmedia links

5 replies · Started by Torsten on February 6, 2023

Viewing posts 1–6 of 6

Hello,

I would like to have at the socialmedia links the rel="me" attribute. Only this is not possible, not even via html.

What is the reason for this? And how can this be done?

Best regards

Torsten

Hi there,

How did you ad the social media links? Are you using the buttons block of Generateblocks?

If so, we can make it work using a PHP snippet.

Let me know!

Hello Ying,

thanks for the quick reply.

I use the buttons block of Generateblocks.

When I insert the rel="me" attribute with html instead of visual an error is reported.

Best regards

Torsten

Yes, the blocks can not be edited as HTML simply.

Try this:
1. When you add the link, select nofollow.

2. Add a CSS class to the button block, eg. social-link, so we can target the block in the PHP of step 3.
https://wordpress.com/support/wordpress-editor/adding-additional-css-classes-to-blocks/

3. Add this PHP snippet to replace the nofollow with me:

add_filter( 'render_block', function( $block_content, $block ) {
	
    if ( ! empty( $block['attrs']['className'] ) && strpos( $block['attrs']['className'], 'social-link' ) !== false  ) {		
		
		$block_content = str_replace('nofollow','me', $block_content );
	}
   return $block_content  ;
}, 10, 2 );

Hello Ying,

works perfectly :-)

Thank you for the extremely fast solution.

Best regards

Torsten

No Problem, glad to help :)

This archived topic is closed to new replies.