Created
April 23, 2021 18:08
-
-
Save kodie/bd1ca18b73a131805d357d21bccaaeee to your computer and use it in GitHub Desktop.
Use a datalist in place of a select dropdown for wp_dropdown_users in WordPress
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 | |
// Use a datalist in place of a select dropdown for wp_dropdown_users | |
add_filter('wp_dropdown_users', 'wp_dropdown_users_datalist'); | |
function wp_dropdown_users_datalist($html) { | |
preg_match("/name='(.*?)'/", $html, $name); | |
preg_match("/id='(.*?)'/", $html, $id); | |
$html = str_replace(array('<select', '/select>'), array('<datalist', '/datalist>'), $html); | |
$html = preg_replace("/id='$id[1]'/", "id='$id[1]-list'", $html); | |
$html = preg_replace("/name='$name[1]'/", '', $html); | |
$html = "<input list='$id[1]-list' id='$id[1]' name='$name[1]' />\n" . $html; | |
return $html; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment