WordPress date picker field
Sometimes you need to use a date field to let enter a valid date, to avoid writing many codes yourself you may use WordPress’ date picker, in fact, it is the date picker of jQuery. Now let me show you how to add a WordPress date picker field.
Just several lines codes you will have a date picker field.
function waytowp_enqueue_scripts(){
wp_enqueue_script('jquery-ui-datepicker');
wp_enqueue_style('jquery-style', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css');
}
add_action( 'wp_enqueue_scripts', 'waytowp_enqueue_scripts' );
add_action( 'admin_enqueue_scripts', 'waytowp_enqueue_scripts' ); //for using date picker in dasbhoard
In your js file, you need to add the following codes.
$(".waytowp-date").datepicker({
dateFormat : 'dd/mm/yy'
});
In your HTML codes, add a date field as the following.
<input type="text" name="waytowp_date" value="" class="waytowp-date"/>
Post a Comment