In this article I read, that using <a href="" target="blank">
is related to some security issues. They recommend rel=noopener
.
How do I implement this in my WP-Installation? Which file is the relevant one? Thank you.
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.
Sign up to join this communityIn this article I read, that using <a href="" target="blank">
is related to some security issues. They recommend rel=noopener
.
How do I implement this in my WP-Installation? Which file is the relevant one? Thank you.
Since WordPress 5.1 (see #43187) it ships with the wp_targeted_link_rel()
function, that adds noreferrer
and noopener
relation values to all anchor elements that have a target
.
This function is used to filter through the various input data just before saving it, e.g.
Since 5.2 the following improvements are made:
There are open tickets to further refine it, e.g.
data-target
attribute.target
.If you have some custom user input that allows external links, then you could use:
$text = wp_targeted_link_rel( $text );
to handle it.
The default relation values 'noopener noreferrer'
are also filterable through the wp_targeted_link_rel
filter.
"Wich file is the relevant one" = All files that allow user generated content to be viewed.
You have to change hook into the_content to change the URLs and add noopener
There is a great answer here: How to add nofollow on all external links without plugin? (and here: A plugin for having rel="nofollow" in posts? ) you should look into.