I have a sidebar. Till now I am calling this as

dynamic_sidebar( 'home-left-widget-area' ); 

and this shows data in <li>. But I need data in <option> .

How to store values in array so I can use <option>

  • I do not understand why you would insert widgets into <option> tags. Are you trying to put the whole widget into a <select> menu? What are you trying to do?
    – s_ha_dum
    Jun 25 '13 at 14:31
  • yes I am working on responsive theme so I need all the sidebar values in <select> . So I need all values in array as we get of menus
    – Bhuvnesh
    Jun 25 '13 at 14:32
  • 1
    I am 99% sure that is going to result in very broken markup. I would suggest you rethink your approach.
    – s_ha_dum
    Jun 25 '13 at 14:40
  • can you tell me how to store values in array when I use dynamic_sidebar()
    – Bhuvnesh
    Jun 25 '13 at 14:41
  • the html markup of the sidebar is set in the register_sidebar() codes usually in functions.php of the theme. alternatively possibly consider to program as a custom widget, whatever you want to create.
    – Michael
    Jun 25 '13 at 15:05

Widgets echo data. Take a look at the widget method of some of the default widgets, like this one.

You can't save that data to an array without writing your own function to process the widgets and using output buffering where the widgets themselves echo content. And sidebars/sidebar-widgets are complicated. That is not an easy function to write.

Sidebars are not meant to do what you want to do and even if you got it working your markup would be broken since you would be shoving whole widgets into a <select>. You'd have all kinds of things inside the <select> menu that are not supposed to be there. Try pushing something like this through the w3c validator:


That is something like what you will get.

What you are trying to do is complicated and wrong and browsers may not parse the markup correctly enough to do what you expect it to do anyway. I'd bet they would not. Complicated chunks of block level content are not supposed to be inside a select menu.

You do not need markup in a select menu to have a responsive theme. You need to rethink what you are doing.

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.