Is there a hook or filter yet for Gutenberg Block Editor to not auto-add Noreferrer to links with a target?

Just for others that see this post, as I am sure you are already aware, the noreferrer is added as a security fix for IE and Edge browsers and a few others, that do not support the rel=”noopener” security fix for links that are opened in a new tab.

To remove the noreferrer, it is still a preg_replace. I added this to functions.php (backing it up first).

//This code removes noreferrer from your new or updated posts
add_filter( 'wp_targeted_link_rel', 'my_targeted_link_rel_remove_noreferrer');
function my_targeted_link_rel_remove_noreferrer( $rel_values ) {
return preg_replace( '/noreferrer\s*/i', '', $rel_values );
}

The first time I was testing, I had to add a priority to the filter call (below code) to make it work, not sure that “999” was really necessary, but now when I test it seems to work without it.

//This code removes noreferrer from your new or updated posts
add_filter( 'wp_targeted_link_rel', 'my_targeted_link_rel_remove_noreferrer', 999);
function my_targeted_link_rel_remove_noreferrer( $rel_values ) {
return preg_replace( '/noreferrer\s*/i', '', $rel_values );
}

Here is the link to the full post.
https://wpbloggerassist.com/remove-noreferrer-in-gutenberg-from-the-latest-wordpress-update/

Editing to add I found another code here:

// from: https://tinygod.pt/gutenberg-adds-noopener-noreferrer-to-links/
function my_links_control( $rel, $link ) {
return false;
}
add_filter( ‘wp_targeted_link_rel’, ‘my_links_control’, 10, 2 );

NOTE: This does not remove existing noreferrer links, you still need to go to posts, remove the “noreferrer” text and update.

This third code will not auto-add any rel attributes. So it is up to you to make sure to add the rel=”noopener” manually.

Leave a Comment