wpseek.com
WordPress开发者和主题制作者的搜索引擎



links_add_target › WordPress Function

Since2.7.0
已弃用n/a
links_add_target ( $content, $target = '_blank', $tags = array('a') )
参数: (3)
  • (string) $content String to search for links in.
    Required: Yes
  • (string) $target The target to add to the links.
    Required: No
    默认: '_blank'
  • (string[]) $tags An array of tags to apply to.
    Required: No
    默认: array('a')
返回:
  • (string) The processed content.
定义在:
文档:

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.


源码

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