[wp-trac] [WordPress Trac] #46580: Is there a reason we add noopener noreferrer on all anchor tags with target=?
WordPress Trac
noreply at wordpress.org
Wed Mar 20 22:20:45 UTC 2019
#46580: Is there a reason we add noopener noreferrer on all anchor tags with
target=?
-----------------------------+-----------------------------
Reporter: heller_benjamin | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: 5.1
Severity: minor | Keywords:
Focuses: |
-----------------------------+-----------------------------
{{{#!php
<?php
/**
* Adds rel noreferrer and noopener to all HTML A elements that have a
target.
*
* @param string $text Content that may contain HTML A elements.
* @return string Converted content.
*/
function wp_targeted_link_rel( $text ) {
// Don't run (more expensive) regex if no links with targets.
if ( stripos( $text, 'target' ) !== false && stripos( $text, '<a '
) !== false ) {
$text = preg_replace_callback(
'|<a\s([^>]*target\s*=[^>]*)>|i', 'wp_targeted_link_rel_callback', $text
);
}
return $text;
}
}}}
I have run into an issue with a Gutenberg block failed to validate because
target="_self" is getting rel="noopener noreferrer" added. Is there a
reason we cannot put a strpos conditional for "_blank" or something
similar?
--
Ticket URL: <https://core.trac.wordpress.org/ticket/46580>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list