WordPress.org

Make WordPress Core

Opened 2 months ago

Last modified 8 weeks 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:

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 2 months ago.
Screenshot

Download all attachments as: .zip

Change History (3)

@fabeyg
2 months ago

Screenshot

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

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

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


8 weeks ago

Note: See TracTickets for help on using tickets.