Builds a string of HTML attributes from an array of key/value pairs.
Description
Empty values are ignored.
Parameters
$atts
arrayoptional- An array of HTML attribute key/value pairs.
Default:
array()
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
Version | Description |
---|---|
6.3.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.