0

I cant seem to find any complete tutorial that shows how to add / save/ retrieve a fields to any widget. Can someone please show a simple example how to add a simple select , save the data and retrieve it in front.

All I got so far is this http://prntscr.com/76d051

add_action('in_widget_form', 'add_widget_fields');
function add_widget_fields(){


    $html ='<select class="custom_widget_select" name="dont know">';
    $html .='<option value="blue">Blue</option>';
    $html .='<option value="red">Red</option>';
    $html .='<option value="green">Green</option>';
    $html .='</select>';

    echo $html;

}

I dont know what name to use , how to retrieve it once is saved and how to display it in front for all widgets.

I just need to add simple select to display list of additional widget styles. and I would like to do this trough theme functions.php rather than creating a full blown plugin.

Any help is appreciated.

5
  • How to store widget fields data as an array? contains a minimal yet complete example. You just have to change the form element.
    – fuxia
    May 17, 2015 at 20:44
  • @toscho I saw that but that is a plugin , I just need to add simple select to display list of additional widget styles. and I would like to do this trough theme functions.php rather than creating a full blown plugin.
    – Benn
    May 17, 2015 at 20:51
  • Then just use the code in a theme without plugin headers. What is stopping you?
    – fuxia
    May 17, 2015 at 21:02
  • a humble I dont know how to.
    – Benn
    May 17, 2015 at 21:07
  • @toscho , just tested your plugin , that is not it , I need to add select to all available widgets , not make widget with addable fields
    – Benn
    May 17, 2015 at 21:36

0

Your Answer

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

Browse other questions tagged or ask your own question.