admin管理员组文章数量:1122846
Wordpress adds "noreferrer" to all links that open in a new tab. This started before Gutenberg and a TinyMCE filter was provided to fix it. This no longer works for Gutenberg. They have a new wp_targeted_link_rel filter too that only works for the classic editor.
I manually removed it from all my links and all was fine on WP 5.0. Upon updating to WP 5.1 it was added back to all of my links after updating the posts. This is a nightmare.
The reason to remove it has to do with tracking the originating domain with affiliate networks. Even those that use affiliate ID's as URL parameters still demand that the referrer be an approved domain.
Has anyone found a way to stop this on Gutenberg yet?
Wordpress adds "noreferrer" to all links that open in a new tab. This started before Gutenberg and a TinyMCE filter was provided to fix it. This no longer works for Gutenberg. They have a new wp_targeted_link_rel filter too that only works for the classic editor.
I manually removed it from all my links and all was fine on WP 5.0. Upon updating to WP 5.1 it was added back to all of my links after updating the posts. This is a nightmare.
The reason to remove it has to do with tracking the originating domain with affiliate networks. Even those that use affiliate ID's as URL parameters still demand that the referrer be an approved domain.
Has anyone found a way to stop this on Gutenberg yet?
Share Improve this question asked Mar 12, 2019 at 23:57 Timmy D.Timmy D. 336 bronze badges 6 | Show 1 more comment1 Answer
Reset to default 0Just 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.
版权声明:本文标题:Is there a hook or filter yet for Gutenberg Block Editor to not auto-add Noreferrer to links with a target? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736286957a1927778.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
noreferrer
removed out of curiosity? – Tom J Nowell ♦ Commented Mar 13, 2019 at 1:29createLinkFormat
in javascript, the solution here is almost certainly going to either be a JS one, or something that runs onthe_content
, but I don't see why you would want to remove it, some context on your question as to why would be super helpful and better inform any answers you might get – Tom J Nowell ♦ Commented Mar 13, 2019 at 1:36