Make WordPress Core

Opened 15 months ago

Last modified 15 months ago

#47202 new defect (bug)

Gutenberg doesn't honor the wp_targeted_link_rel Filter

Reported by: fabeyg Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Editor Keywords:
Focuses: Cc:


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:

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:


Attachments (1)

screenshot_rel-attr.jpg (31.4 KB) - added by fabeyg 15 months ago.

Download all attachments as: .zip

Change History (3)

15 months ago


#1 @starvoters1
15 months 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.

function filter_save_link_rel ( $rel, $link ) {
  return 'noopener';
add_filter( 'wp_targeted_link_rel', 'filter_save_link_rel', 999 );
Last edited 15 months ago by starvoters1 (previous) (diff)

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

15 months ago

Note: See TracTickets for help on using tickets.