links_add_target( string $content, string $target = '_blank', array $tags = array('a') )
Adds a Target attribute to all links in passed content.
Description Description
This function by default only applies to <a>
tags, however this can be modified by the 3rd param.
_NOTE:_ Any current target attributed will be stripped and replaced.
Parameters Parameters
- $content
-
(string) (Required) String to search for links in.
- $target
-
(string) (Optional) The Target to add to the links.
Default value: '_blank'
- $tags
-
(array) (Optional) An array of tags to apply to.
Default value: array('a')
Return Return
(string) The processed content.
Source Source
File: wp-includes/formatting.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)([^>]*)>!i", '_links_add_target', $content ); }
Expand full source code Collapse full source code View on Trac
Changelog Changelog
Version | Description |
---|---|
2.7.0 | Introduced. |