- This topic has 8 replies, 2 voices, and was last updated 3 years, 11 months ago by
Ying.
-
AuthorPosts
-
May 10, 2022 at 2:05 pm #2215642
crosby87
Hi there,
I would like to remove
noreferrerfrom 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
noopenerandsponsored. 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?
May 10, 2022 at 2:09 pm #2215647crosby87
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 takesnoreferrerand 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!
May 10, 2022 at 5:53 pm #2215728Ying
StaffCustomer SupportHi 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.
May 11, 2022 at 10:37 am #2216752crosby87
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 sponsoredIs 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!
May 11, 2022 at 11:10 am #2216783Ying
StaffCustomer Support1. 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.
May 11, 2022 at 1:22 pm #2216906crosby87
Hi Ying,
Many thanks.
Is there also a possibility to make the code as such that it ONYL removes
'noreferrer ', 'noreferrer', ' noreferrer'if thesponsoredtag is there?So if its only
noopener noreferrerit can stay like that. But as soon as it isnoopener noreferrer sponsoredthen I would likenoreferrerto be removed.This
$remove_words = array('noreferrer ', 'noreferrer', ' noreferrer');should stay the same in case order of the three tags differs.Thanks a lot!
May 11, 2022 at 1:31 pm #2216910Ying
StaffCustomer SupportDon’t think the simple
str_replacecan do this.How did you add the
nonreferralas I’m not seeing the option in GB button.Let me know 🙂
May 12, 2022 at 1:18 pm #2217944crosby87
Ying,
noreferralis 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
noreferrerifsponsoredis also there.Thanks!
May 12, 2022 at 6:23 pm #2218059Ying
StaffCustomer SupportTry this, it seems the
sponsoredis always coming after thenoreferrer, 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 ); -
AuthorPosts
- You must be logged in to reply to this topic.