wpseek.com
Bazujące na WordPress narzędzie wyszukiwania dla deweloperów i twórców motywów.



links_add_target › WordPress Function

Od2.7.0
Przestarzałyn/a
links_add_target ( $content, $target = '_blank', $tags = array('a') )
Parametry: (3)
  • (string) $content String to search for links in.
    Wymagane: Tak
  • (string) $target The target to add to the links.
    Wymagane: Nie
    Domyślny: '_blank'
  • (string[]) $tags An array of tags to apply to.
    Wymagane: Nie
    Domyślny: array('a')
Powrót:
  • (string) The processed content.
Zdefiniowane na:
Codex:

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.


Źródło

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