links_add_target() WP 1.0
Adds a Target attribute to all links in passed content.
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.
1 time = 0.000099s = very fast | 50000 times = 0.38s = very fast | PHP 7.0.8, WP 4.6
No Hooks.
Return
String. The processed content.
Usage
links_add_target( $content, $target, $tags );
- $content(string) (required)
- String to search for links in.
- $target(string)
- The Target to add to the links.
Default: '_blank' - $tags(string[])
- An array of tags to apply to.
Default: array( fooo )
Notes
- Global. String. $_links_add_target
Changelog
Since 2.7.0 | Introduced. |
Code of links_add_target() links add target WP 5.6
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 Functions
From category: Formatting
- absint()
- add_magic_quotes()
- antispambot()
- backslashit()
- balanceTags()
- capital_P_dangit()
- convert_smilies()
- ent2ncr()
- force_balance_tags()