Make WordPress Core

Opened 6 years ago

Closed 4 years ago

#47202 closed defect (bug) (reported-upstream)

Gutenberg doesn't honor the wp_targeted_link_rel Filter

Reported by: fabeyg's profile fabeyg Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Editor Keywords:
Focuses: Cc:

Description

There is some inconsistent behaviour in how Gutenberg honors the wp_targeted_link_rel Filter.

In my filter I outpout just "noopener" instead of "noreferrer noopener" for the rel attribute Links that oben in a new tab/window:

<?php
function filter_save_link_rel ( $rel, $link ) {
  return 'noopener';
}
add_filter( 'wp_targeted_link_rel', 'filter_save_link_rel', 10, 2 );

When I write a new Link in a Gutenberg Paragraph Block the Editor automatically adds the rel="noopener noreferrer" attribute to the link.

However, when I remove the rel attribute in the HTML Block Editing Mode, the attribute is replaced with the correct value according to the filter.

Here is a screenshot of a fresh WordPress install displaying this behaviour:

https://drive.google.com/file/d/1SslbjYcyd2SaQA9-ltSsPMbNojB5XXLc

Attachments (1)

screenshot_rel-attr.jpg (31.4 KB) - added by fabeyg 6 years ago.
Screenshot

Download all attachments as: .zip

Change History (5)

@fabeyg
6 years ago

Screenshot

#1 @starvoters1
6 years ago

I am having the same issue on both classic editor and Gutenberg and ended up coding a workaround to remove "noreferrer", would be great if this filter could be fixed so we can just use this instead.

Editing to add, actually if I change the priority to 999, and remove the # of args setting it seems to be working fine on both Gutenberg and Classic, not sure of the priority needed. It may depend on theme and plugins installed too.

<?php
function filter_save_link_rel ( $rel, $link ) {
  return 'noopener';
}
add_filter( 'wp_targeted_link_rel', 'filter_save_link_rel', 999 );
Last edited 6 years ago by starvoters1 (previous) (diff)

This ticket was mentioned in Slack in #core by desrosj. View the logs.


6 years ago

#3 @wpwebdevj
4 years ago

Is there any update on this? I am having the same problem. I even tried installing WordPress 5.6 beta (which has removed noreferrer from wp_targeted_link_rel) but Gutenberg is still adding it.

#4 @SergeyBiryukov
4 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to reported-upstream
  • Status changed from new to closed

Hi there, welcome to WordPress Trac! Thanks for the report.

Please note that any issues for the block editor are tracked on GitHub: https://github.com/WordPress/gutenberg/.

Looks like there is already a Gutenberg issue for this: https://github.com/WordPress/gutenberg/issues/26914, so I'm closing the ticket as reported-upstream.

Note: See TracTickets for help on using tickets.