links_add_target

The timeline below displays how wordpress function links_add_target has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.3

/**
 * Adds a target attribute to all links in passed content.
 *
 * 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.
 *
 * @since 2.7.0
 *
 * @global string $_links_add_target
 *
 * @param string   $content String to search for links in.
 * @param string   $target  The target to add to the links.
 * @param string[] $tags    An array of tags to apply to.
 * @return string The processed content.
 */
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);
}

WordPress Version: 5.6

/**
 * 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.
 *
 * @since 2.7.0
 *
 * @global string $_links_add_target
 *
 * @param string   $content String to search for links in.
 * @param string   $target  The Target to add to the links.
 * @param string[] $tags    An array of tags to apply to.
 * @return string The processed content.
 */
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);
}

WordPress Version: 5.4

/**
 * 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.
 *
 * @since 2.7.0
 *
 * @global string $_links_add_target
 *
 * @param string   $content String to search for links in.
 * @param string   $target  The Target to add to the links.
 * @param string[] $tags    An array of tags to apply to.
 * @return string The processed content.
 */
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);
}

WordPress Version: 4.3

/**
 * 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.
 *
 * @since 2.7.0
 *
 * @global string $_links_add_target
 *
 * @param string $content String to search for links in.
 * @param string $target  The Target to add to the links.
 * @param array  $tags    An array of tags to apply to.
 * @return string The processed content.
 */
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);
}

WordPress Version: 4.1

/**
 * 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.
 *
 * @since 2.7.0
 *
 * @param string $content String to search for links in.
 * @param string $target The Target to add to the links.
 * @param array $tags An array of tags to apply to.
 * @return string The processed content.
 */
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);
}

WordPress Version: 3.8

/**
 * 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.
 *
 * <b>NOTE:</b> Any current target attributed will be stripped and replaced.
 *
 * @since 2.7.0
 *
 * @param string $content String to search for links in.
 * @param string $target The Target to add to the links.
 * @param array $tags An array of tags to apply to.
 * @return string The processed content.
 */
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);
}

WordPress Version: 3.7

/**
 * 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.
 *
 * <b>NOTE:</b> Any current target attributed will be stripped and replaced.
 *
 * @since 2.7.0
 *
 * @param string $content String to search for links in.
 * @param string $target The Target to add to the links.
 * @param array $tags An array of tags to apply to.
 * @return string The processed content.
 */
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);
}