admin管理员组

文章数量:1122832

I'm using Classic Editor (not Gutenberg) and WP is adding rel="noopener noreferrer" to ALL the links, whether it is target="" or target="_blank" or target="_self"!

I want to remove noreferrer from my affiliate links - please help! Thank you!

I'm using Classic Editor (not Gutenberg) and WP is adding rel="noopener noreferrer" to ALL the links, whether it is target="" or target="_blank" or target="_self"!

I want to remove noreferrer from my affiliate links - please help! Thank you!

Share Improve this question asked Jun 1, 2019 at 11:14 NickNick 11 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

So WordPress provides a way to adjust these programmatically, but it's done at the time of post save, not post render, so the changes will only apply once you add the code snippet to your site, and the go and re-save your post(s).

And, it's only available from WP 5.1+

Here's the code snippet (add it to your themes functions.php if you don't have any other way already)


        add_filter( 'wp_targeted_link_rel', function ( $sRels ) {
            $aRels = preg_split( '#\s+#', $sRels );
            if ( is_array( $aRels ) ) {
                $nKey = array_search( 'noreferrer', array_map( 'strtolower', $sRels ) );
                if ( is_numeric( $nKey ) ) {
                    unset( $aRels[ $nKey ] );
                }
                $sRels = implode( ' ', $aRels );
            }
            return $sRels;
        }, 10000 );

Again, once this is added to your site, then you'll need to manually go in and re-save your post(s) and this should update your links by removing noreferrer.

本文标签: permalinksWP adding noopener and noreferrer to all links