Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren



the_title_attribute ›

Seit2.3.0
Veraltetn/v
the_title_attribute ( $args = '' )
Parameter:
  • (string|array) $args { Title attribute arguments. Optional.
    Erforderlich: Nein
    Standard: (leer)
Gibt zurück:
  • (string|void) String when echo is false.
Definiert in:
Codex:

Sanitize the current title when retrieving or displaying.

Works like the_title(), except the parameters can be in a string or an array. See the function for what can be override in the $args parameter.

The title before it is displayed will have the tags stripped and esc_attr() before it is passed to the user or displayed. The default as with the_title(), is to display the title.



Quellcode

function the_title_attribute( $args = '' ) {
	$defaults = array(
		'before' => '',
		'after'  => '',
		'echo'   => true,
		'post'   => get_post(),
	);
	$r        = wp_parse_args( $args, $defaults );

	$title = get_the_title( $r['post'] );

	if ( strlen( $title ) == 0 ) {
		return;
	}

	$title = $r['before'] . $title . $r['after'];
	$title = esc_attr( strip_tags( $title ) );

	if ( $r['echo'] ) {
		echo $title;
	} else {
		return $title;
	}
}