Site logo

Archived topic

Remove norefferer from generateblocks button

8 replies · Started by crosby87 on May 10, 2022

Viewing posts 1–9 of 9

Hi there,

I would like to remove noreferrer from the GenerateBlocks button only.

I would the following link where Tom posted the code below:

add_filter( 'render_block', function( $block_content, $block ) {
    if ( 'generateblocks/button' === $block['blockName'] ) {
        $block_content = str_replace( 'noreferrer', '', $block_content );
    }

    return $block_content;
}, 10, 2 );

Works fine, however, I noticed that the code adds an extra space between noopener and sponsored. Normally, these are separated by only one space, and now I see two.

See a screenshot of the code here: click

Could you please help remove one of the spaces?

Bit late, but now I try to understand the code of Tom (sorry, I do not have any programming knowledge).
If I understand correctly it basically takes noreferrer and replaces it with an empty space, that's why there are now two spaces.

1. Is there a way to remove this?
2. Does this impact my website's performance in any negative way?

Thanks!

Hi there,

1. The code replaces the word with "nothing", but it doesn't remove the space which comes with the word.

So you can edit the code to include the space in the word that you want to replace:

add_filter( 'render_block', function( $block_content, $block ) {
    if ( 'generateblocks/button' === $block['blockName'] ) {
        $block_content = str_replace( 'noreferrer ', '', $block_content );
    }

    return $block_content;
}, 10, 2 );

2. I'm not an expert of SEO, so I'm not sure will there be impact or not. Worth doing some research.

Hi,

Thanks!

1. Good one, but what if html tags are like this noopener noreferrer? Since you now have a space in the code in won't remove noreferrer, right? It only removes it when it's like this for example: noopener noreferrer sponsored

Is it possible to change that it removes it in both cases?

2. I did not mean whether this will have an impact on SEO. I mean whether having an extra space in thoce (i.e noopener noreferrer) has any impact on website speed, or from any other technical/coding point of view?

Thanks!

1. You can try something like this to include all kinds of scenarios:

add_filter( 'render_block', function( $block_content, $block ) {
    if ( 'generateblocks/button' === $block['blockName'] ) {
	$remove_words = array('noreferrer ', 'noreferrer', ' noreferrer');
        $block_content = str_replace( $remove_words, '', $block_content );
    }

    return $block_content;
}, 10, 2 );

2. No, I don't think so.

Hi Ying,

Many thanks.

Is there also a possibility to make the code as such that it ONYL removes 'noreferrer ', 'noreferrer', ' noreferrer' if the sponsored tag is there?

So if its only noopener noreferrer it can stay like that. But as soon as it is noopener noreferrer sponsored then I would like noreferrer to be removed.

This $remove_words = array('noreferrer ', 'noreferrer', ' noreferrer'); should stay the same in case order of the three tags differs.

Thanks a lot!

Don't think the simple str_replacecan do this.

How did you add the nonreferral as I'm not seeing the option in GB button.

Let me know :)

Ying,

noreferral is automatically added by the GeneratePress button. Even if I try to edit it as HTML within wordpress and remove it, it adds it back automatically.

The code above works fine, however, I wonder if it can be modified in a way that it only removes noreferrer if sponsored is also there.

Thanks!

Try this, it seems the sponsoredis always coming after the noreferrer, so below code should work:

add_filter( 'render_block', function( $block_content, $block ) {
    if ( 'generateblocks/button' === $block['blockName'] ) {
		$remove_words = 'noreferrer sponsored';
        $block_content = str_replace( $remove_words, 'sponsored', $block_content );
    }

    return $block_content;
}, 10, 2 );
This archived topic is closed to new replies.