Add the following line of code to enqueue the jquery ui datepicker library from your plugin:
wp_enqueue_script('jquery-ui-datepicker');
You can download the stylesheet file from the jquery ui library site and include it in your plugin. You would then enqueue the CSS file like the following:
wp_enqueue_style('jquery-ui-css', 'http://www.example.com/your-plugin-path/css/jquery-ui.css');
Alternatively, You can include the jquery ui CSS from Google (you don’t need to ship the CSS files with your plugin if you go via this route):
wp_enqueue_style('jquery-ui-css', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css');
Add the following JQuery code to your javascript file so it attaches the datepicker to any fields with a class of “custom_date”:
<script type="text/javascript">
jQuery(document).ready(function($) {
$('.custom_date').datepicker({
dateFormat : 'yy-mm-dd'
});
});
</script>
Now, you can simply add class “custom_date” to the date fields in the HTML code and it will show a date picker calender when a user clicks on that field.
<input type="text" class="custom_date" name="start_date" value=""/>