Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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>

share|improve this question
    
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
add comment

1 Answer

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:

<select>
  <option>
   <div><p><em>Hi</em></p></div>
   <li>
     hello
   </li>
  </option>
</select>

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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