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">

Is there any chance for me?

  • 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 Dec 28 '15 at 8:57
  • 1
    Either create your own select and option elements, or add the attribute per JavaScript. There is no other way.
    – fuxia
    Dec 28 '15 at 8:59

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);
wp_dropdown_categories(); // test

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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