I have a dropdown menu for selecting categories in a widget that I am working on. Everything is working and options are being saved in the database. What I am trying to do now is add a blank option instead of it being automatically set when you click save. In this situation, the user might not want to set a category.

  $this->categories = get_categories();
            foreach ( $this->categories as $cat ) {
                $selected = ( $cat->term_id == esc_attr( $category ) ) ? ' selected = "selected" ' : '';
                $option = '<option '.$selected .'value="' . $cat->term_id;
                $option = $option .'">';
                $option = $option .$cat->name;
                $option = $option .'</option>';
                echo $option;

How can I append a blank option to the select?

1 Answer 1


I presume there is an open option html element before that code provided. After that select tag is opened and before you run through that loop echo out a blank option with value=""

  • no, There is only the code I posted above. That alone generates my select box.
    – Jamie
    Commented Jan 9, 2015 at 4:15

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.