1

I am currently creating a plugin and need one of the fields to be a drop down calendar picker. Will I have to build this as well or is there a hook I can use to use something already produced by WordPress?

  • Hey @Max, does your question been answered ? If yes, please accept an answer ! Have a good day ! – Jonathan Lafleur Jun 17 '14 at 14:18
5

jQuery Datepicker is included in WP Core, you can add it to your functions.php (for themes) or index.php (for plugins)

function styles_scripts() {
    wp_enqueue_script('jquery-ui-datepicker');
    // Enqueue some theme-roller or default style...
    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', 'styles_scripts', 11 );

Than in the HTML part where you need the datepicker

<input type="text" id="MyDate" name="MyDate" value=""/>

And finally in your Javascript

jQuery(document).ready(function() {
    jQuery('#MyDate').datepicker({
        dateFormat : 'dd-mm-yy'
    });
});

This code is not tested, I just typed it here and hope it work well, let me know if you need more information or correction.

| improve this answer | |
  • I think that your answer should be an edition of the @WilltheWebMechanic answer that was made before yours. – cybmeta Jun 12 '14 at 17:24
  • 1
    This answer predates the other by 4 minutes, @cybmeta. – Johannes Pille Jun 12 '14 at 17:32
  • Oooops, yes, sorry, I don't know why I made the reverse reading. I feel quite silly ;) – cybmeta Jun 12 '14 at 18:21
2

The jQuery UI datepicker is included in WordPress. While not really a 'dropdown' calendar picker, it should meet your needs and can be easily configured to reflect localizations of wherever it is running.

enqueue it with wp_enqueue_script( 'jquery-ui-datepicker' ); or add it as a dependency as needed to js that your plugin is loading. You'll need to ensure that there is some css available for it as well.

| improve this answer | |
  • 2
    You should add some example code. – cybmeta Jun 12 '14 at 17:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.