• I use Gutenberg Editor and (Block) Button Elements. The Button links open in new tab. They then have link rel noreferrer noopener. How can i make it, that the links have only “noopener”.?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Hey @magat93! This seems to be a bug, with some discussion on Github about it.

    An immediate option is to use a plugin to remove ‘noreferrer’ from your link. You can find quite a few plugins like this on the plugin directory.

    Thread Starter magat93

    (@magat93)

    Hi @properlypurple, thanks for your reply. All the plugins in the directory are old (not tested with the current wordpress versions) or only add “noreferrer” but not remove it ??

    Kavya Gokul

    (@properlypurple)

    @magat93 I also see there’s some code in these two comments on Github, that can help with this:

    You can use a plugin like Code Snippets to add custom code to your site.

    Thread Starter magat93

    (@magat93)

    Hi?@properlypurple,?i inserted the code in functions.php, but it doesn′t help. I also tried another code where i found, but it also not works.

    function removing_noreferrer_link_rel( $rel_values ) {
    return 'noopener';
    }
    add_filter( 'wp_targeted_link_rel', 'removing_noreferrer_link_rel', 999 );
    Kavya Gokul

    (@properlypurple)

    Hi @magat93 ! I was talking about the code from another comment, one of the ones I linked above. The code I’m referring to is below:

    /**
    * Hook to the the_content filter to modify/improve the output content * and hotfix some bugs which are present in Gutenberg
    */
    add_filter( 'the_content', static function( string $content ): string {
    
    /**
    * Remove the noreferrer attribute from the a tag when the target attribute is set to * @link: https://github.com/WordPress/gutenberg/issues/26914#issuecomment-949431820
    */
    $replace = [
        ' noreferrer' => '',
        'noreferrer'  => ''
    ];
    
    $content = strtr($content, $replace);
    
    return $content;
    } );

    Thread Starter magat93

    (@magat93)

    Hi?@properlypurple,?yes i know. i tried the code from Github and inserted it in my functions.php. but this don′t work.

    Kavya Gokul

    (@properlypurple)

    Hey @magat93! I have just tested this code on a fresh site with the 2024 theme, and it seems to be working fine. I added the code using the Code snippets plugin. (Please see screenshots below):

    Are you using any caching/optimization plugin by any chance, or do you have caching on your host’s end? If yes, you might need to clear the cache and reload the site a few times.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘noreferrer in Buttons’ is closed to new replies.