Title: links_add_target
Published: April 25, 2014
Last modified: May 20, 2026

---

# links_add_target( string $content, string $target = '_blank', string[] $tags = array('a') ): string

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/links_add_target/?output_format=md#description)
 * [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)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/links_add_target/?output_format=md#user-contributed-notes)

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

Adds a target attribute to all links in passed content.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/links_add_target/?output_format=md#description)󠁿

By default, this function only applies to `<a>` tags.
However, this can be modified
via the `$tags` parameter.

_NOTE:_ Any current target attribute will be stripped and replaced.

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

 `$content`stringrequired

String to search for links in.

`$target`stringoptional

The target to add to the links.

Default:`'_blank'`

`$tags`string[]optional

An array of tags to apply to.

Default:`array('a')`

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

 string The processed content.

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

    ```php
    function links_add_target( $content, $target = '_blank', $tags = array( 'a' ) ) {
    	global $_links_add_target;
    	$_links_add_target = $target;
    	$tags              = implode( '|', (array) $tags );
    	return preg_replace_callback( "!<($tags)((\s[^>]*)?)>!i", '_links_add_target', $content );
    }
    ```

[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#L5472)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/formatting.php#L5472-L5477)

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

| Used by | Description | 
| [install_plugin_information()](https://developer.wordpress.org/reference/functions/install_plugin_information/)`wp-admin/includes/plugin-install.php` |

Displays plugin information in dialog box form.

  |

## 󠀁[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](https://developer.wordpress.org/reference/functions/links_add_target/?output_format=md#user-contributed-notes)󠁿

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/functions/links_add_target/?output_format=md#comment-content-6588)
 2.   [Saurabh Sharma](https://profiles.wordpress.org/xconsau/)  [  3 years ago  ](https://developer.wordpress.org/reference/functions/links_add_target/#comment-6588)
 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%2Flinks_add_target%2F%23comment-6588)
    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%2Flinks_add_target%2F%23comment-6588)
 4. Add `target="_blank"` to the `get_the_category_list()` output.
 5.     ```php
        $cat_links = get_the_category_list();
        $modified = links_add_target( $cat_links ); // the 'target' parameter is omitted as it is _blank by default
        echo $modified;
        ```
    
 6.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Flinks_add_target%2F%3Freplytocom%3D6588%23feedback-editor-6588)

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