wpseek.com
Outil de recherche WordPress pour les développeurs et auteurs de thèmes



links_add_target › WordPress Function

Depuis2.7.0
Dépréciéen/a
links_add_target ( $content, $target = '_blank', $tags = array('a') )
Paramètres: (3)
  • (string) $content String to search for links in.
    Requis: Oui
  • (string) $target The target to add to the links.
    Requis: Non
    Défaut: '_blank'
  • (string[]) $tags An array of tags to apply to.
    Requis: Non
    Défaut: array('a')
Retourne:
  • (string) The processed content.
Défini(e) dans:
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.


Source

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