Last active
July 25, 2017 19:16
-
-
Save n7studios/2f432dd774180ef8428db1c4d8472ce7 to your computer and use it in GitHub Desktop.
Add aria-label to wp_dropdown_categories()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* If the aria-label argument has been specified in a wp_dropdown_categories() call, | |
* output the aria-label option in the <select> | |
* | |
* @since 1.0.0 | |
* | |
* @param string $output HTML Output | |
* @param array $arguments wp_dropdown_category() arguments | |
* @return string Modified HTML Output | |
*/ | |
public function wp_dropdown_cats_aria_label_support( $output, $arguments ) { | |
// Bail if no aria-label argument has been supplied | |
if ( ! isset( $arguments['aria-label'] ) ) { | |
return $output; | |
} | |
// Add aria-label | |
$output = str_replace( '<select ', '<select aria-label="' . sanitize_text_field( $arguments['aria-label'] ) . '"', $output ); | |
// Return | |
return $output; | |
} | |
add_filter( 'wp_dropdown_cats', 'wp_dropdown_cats_aria_label_support', 10, 2 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Example usage of wp_dropdown_categories(), when aria-label | |
* support has been added. | |
* | |
* @since 1.0.0 | |
*/ | |
wp_dropdown_categories( array( | |
// Other wp_dropdown_categories() arguments go here... | |
// Define our aria-label | |
'aria-label' => __( 'ARIA Label Value', 'domain' ), | |
) ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment