WordPress Snippets at WPcustoms

Generate a month select box

this function generates a dropdown select box showing all month.


/**
 * Snippet Name: Generate a month select box
 * Snippet URL: http://www.wpcustoms.net/snippets/generate-month-select-box/
 */
 function month_select_box( $field_name = 'month' ) {
    $month_options = '';
    for( $i = 1; $i <= 12; $i++ ) {
        $month_num = str_pad( $i, 2, 0, STR_PAD_LEFT );
        $month_name = date( 'F', mktime( 0, 0, 0, $i + 1, 0, 0, 0 ) );
        $month_options .= '';
    }
    return '';
}