On this page
links_add_target( string $content, string $target = '_blank', string[] $tags = array('a') ): string
Adds a Target attribute to all links in passed content.
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
$contentstring Required-
String to search for links in.
$targetstring Optional-
The Target to add to the links.
Default:
'_blank' $tagsstring[] Optional-
An array of tags to apply to.
Default:
array('a')
Return
string The processed content.
Source
File: wp-includes/formatting.php. View all references
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 );
}
Related
Used By
| Used By | Description |
|---|---|
| install_plugin_information() wp-admin/includes/plugin-install.php | Displays plugin information in dialog box form. |
Changelog
| Version | Description |
|---|---|
| 2.7.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/links_add_target