Walker_Nav_Menu::build_atts
Builds a string of HTML attributes from an array of key/value pairs. Empty values are ignored.
Method of the class: Walker_Nav_Menu{}
No Hooks.
Returns
String. A string of HTML attributes.
Usage
// protected - for code of main (parent) or child class $result = $this->build_atts( $atts );
- $atts(array)
- An array of HTML attribute key/value pairs.
Default:empty array
Changelog
| Since 6.3.0 | Introduced. |
Walker_Nav_Menu::build_atts() Walker Nav Menu::build atts code WP 6.9.1
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;
}