1

I'm using this jQuery plugin to handle select element on my site: bootstrap-select

Unfortunately, I can't found any option which allow me add a custom attribute to the select element, for e.g:

I want my dropdown look like this:

<select class="dropdown" data-live-search="true">
...
</select>

Is there any chance for me?

2
  • 2
    I don't think you can with wp_dropdown_categories but why not add the attribute at runtime using JavaScript before initiating the bootstrap-select Commented Dec 28, 2015 at 8:57
  • 1
    Either create your own select and option elements, or add the attribute per JavaScript. There is no other way.
    – fuxia
    Commented Dec 28, 2015 at 8:59

1 Answer 1

2

The only filter available is wp_dropdown_cats, which allows you to filter the entire HTML select string and that means trying to string-match markup. That is always a bit questionable. Still...

function dropdown_data_attr_wpse_213033($output){
  return str_replace('<select','<select data-live-search="true"',$output);
}
add_filter('wp_dropdown_cats','dropdown_data_attr_wpse_213033');
wp_dropdown_categories(); // test

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.