Walker_Nav_Menu::build_atts( array $atts = array() ): string

Builds a string of HTML attributes from an array of key/value pairs.

Description

Empty values are ignored.

Parameters

$attsarrayoptional
An array of HTML attribute key/value pairs.

Default:array()

Return

string A string of HTML attributes.

Source

protected function build_atts( $atts = array() ) {
	$attribute_string = '';
	foreach ( $atts as $attr => $value ) {
		if ( false !== $value && '' !== $value && is_scalar( $value ) ) {
			$value             = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value );
			$attribute_string .= ' ' . $attr . '="' . $value . '"';
		}
	}
	return $attribute_string;
}

Changelog

VersionDescription
6.3.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.