WordPress at a glance

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.

  • Global. String. $_links_add_target
✈ 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(array)
An array of tags to apply to.
Default: array(fooo)

Code of links_add_target: wp-includes/formatting.php VER 4.9.8

<?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 );
}

Related Functions

From category: Formatting

No comments
    Hello, !     Log In . Register