Title: wp_targeted_link_rel
Published: February 22, 2019
Last modified: May 20, 2026

---

# wp_targeted_link_rel( string $text ): string

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/wp_targeted_link_rel/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/wp_targeted_link_rel/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/wp_targeted_link_rel/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/wp_targeted_link_rel/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_targeted_link_rel/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/wp_targeted_link_rel/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/wp_targeted_link_rel/?output_format=md#wp--skip-link--target)

This function has been deprecated since 6.7.0.

Adds `rel="noopener"` to all HTML A elements that have a target.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/wp_targeted_link_rel/?output_format=md#parameters)󠁿

 `$text`stringrequired

Content that may contain HTML A elements.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/wp_targeted_link_rel/?output_format=md#return)󠁿

 string Converted content.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/wp_targeted_link_rel/?output_format=md#source)󠁿

    ```php
    function wp_targeted_link_rel( $text ) {
    	_deprecated_function( __FUNCTION__, '6.7.0' );

    	// Don't run (more expensive) regex if no links with targets.
    	if ( false === stripos( $text, 'target' ) || false === stripos( $text, '<a ' ) || is_serialized( $text ) ) {
    		return $text;
    	}

    	$script_and_style_regex = '/<(script|style).*?<\/\\1>/si';

    	preg_match_all( $script_and_style_regex, $text, $matches );
    	$extra_parts = $matches[0];
    	$html_parts  = preg_split( $script_and_style_regex, $text );

    	foreach ( $html_parts as &$part ) {
    		$part = preg_replace_callback( '|<a\s([^>]*target\s*=[^>]*)>|i', 'wp_targeted_link_rel_callback', $part );
    	}

    	$text = '';
    	for ( $i = 0; $i < count( $html_parts ); $i++ ) {
    		$text .= $html_parts[ $i ];
    		if ( isset( $extra_parts[ $i ] ) ) {
    			$text .= $extra_parts[ $i ];
    		}
    	}

    	return $text;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/formatting.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/formatting.php#L3316)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/formatting.php#L3316-L3343)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/wp_targeted_link_rel/?output_format=md#related)󠁿

| Uses | Description | 
| [stripos()](https://developer.wordpress.org/reference/functions/stripos/)`wp-includes/class-pop3.php` |  | 
| [is_serialized()](https://developer.wordpress.org/reference/functions/is_serialized/)`wp-includes/functions.php` |

Checks value to find if it was serialized.

  | 
| [_deprecated_function()](https://developer.wordpress.org/reference/functions/_deprecated_function/)`wp-includes/functions.php` |

Marks a function as deprecated and inform when it has been used.

  |

[Show 1 more](https://developer.wordpress.org/reference/functions/wp_targeted_link_rel/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_targeted_link_rel/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/wp_targeted_link_rel/?output_format=md#changelog)󠁿

| Version | Description | 
| [6.7.0](https://developer.wordpress.org/reference/since/6.7.0/) | Deprecated.  | 
| [5.6.0](https://developer.wordpress.org/reference/since/5.6.0/) | Removed `'noreferrer'` relationship. | 
| [5.1.0](https://developer.wordpress.org/reference/since/5.1.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/wp_targeted_link_rel/?output_format=md#user-contributed-notes)󠁿

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/functions/wp_targeted_link_rel/?output_format=md#comment-content-3154)
 2.   [Jb Audras](https://profiles.wordpress.org/audrasjb/)  [  7 years ago  ](https://developer.wordpress.org/reference/functions/wp_targeted_link_rel/#comment-3154)
 3. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_targeted_link_rel%2F%23comment-3154)
    Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_targeted_link_rel%2F%23comment-3154)
 4. Since WP 5.1.0, we can add `rel` attributes to any bit of HTML code.
     Example used
    in `wp-includes/widgets/class-wp-widget-text.php`:
 5.     ```php
        $text = wp_targeted_link_rel( $text );
        ```
    
 6.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_targeted_link_rel%2F%3Freplytocom%3D3154%23feedback-editor-3154)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_targeted_link_rel%2F)
before being able to contribute a note or feedback.