Title: _links_add_target
Published: April 25, 2014
Last modified: February 24, 2026

---

# _links_add_target( string $m ): string

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/_links_add_target/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/_links_add_target/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/_links_add_target/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/_links_add_target/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/_links_add_target/?output_format=md#changelog)

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

This function’s access is marked private. This means it is not intended for use 
by plugin or theme developers, only by core. It is listed here for completeness.

Callback to add a target attribute to all links in passed content.

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

 `$m`stringrequired

The matched link.

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

 string The processed link.

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

    ```php
    function _links_add_target( $m ) {
    	global $_links_add_target;
    	$tag  = $m[1];
    	$link = preg_replace( '|( target=([\'"])(.*?)\2)|i', '', $m[2] );
    	return '<' . $tag . $link . ' target="' . esc_attr( $_links_add_target ) . '">';
    }
    ```

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

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

| Uses | Description | 
| [esc_attr()](https://developer.wordpress.org/reference/functions/esc_attr/)`wp-includes/formatting.php` |

Escaping for HTML attributes.

  |

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

| Version | Description | 
| [2.7.0](https://developer.wordpress.org/reference/since/2.7.0/) | Introduced. |

## User Contributed Notes

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