Title: Adding the datepicker in events plugin
Last modified: August 22, 2016

---

# Adding the datepicker in events plugin

 *  Resolved [Guido](https://wordpress.org/support/users/guido07111975/)
 * (@guido07111975)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/adding-the-datepicker-in-events-plugin/)
 * Hi,
 * I try to add the datepicker to the date field of my plugin but I cannot make 
   it work.
 * 1) I enqueue scripts:
 *     ```
       function enqueue_date_picker(){
       	wp_enqueue_script( 'my_script', plugins_url( '/js/script.js' , __FILE__ ), array('jquery', 'jquery-ui-core', 'jquery-ui-datepicker'), '1.0', true );
       	wp_enqueue_style('my_style', 'http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css');
       }
       add_action( 'admin_enqueue_scripts', 'enqueue_date_picker' );
       ```
   
 * 2) My input field:
 *     ```
       <input class="widefat" id="date" type="text" name="date" value="<?php echo date( 'j F Y', $event_date ); ?>" />
       ```
   
 * 3) Added file called script.js in folder /js with content:
 *     ```
       $(function() {
       $( "#date" ).datepicker();
       })( jQuery );
       ```
   
 * I notice all scripts are loaded in head section of backend.
    My .js script file
   is loaded in footer section. Nothing happens when I click the date field. So 
   what am I doing wrong here?
 * Have a nice weekend!
 * Guido

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [PhPCentre](https://wordpress.org/support/users/phpcentre/)
 * (@phpcentre)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/adding-the-datepicker-in-events-plugin/#post-5950109)
 * When working with js always use the browser console to help detect errors in 
   your code. Change your js code to this:
 *     ```
       (function($) {
       $( "#date" ).datepicker();
       })( jQuery );
       ```
   
 * or this:
 *     ```
       jQuery(document).ready(function ($) {
         $( "#date" ).datepicker();
       });
       ```
   
 * And one more thing, I would suggest loading your custom script only on your plugin
   page(s), your code will always include your custom js code on all admin pages.
   And let say we have an input field with the id date on another admin/plugin page,
   your code will trigger a ui for that the input field too.
 *  Thread Starter [Guido](https://wordpress.org/support/users/guido07111975/)
 * (@guido07111975)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/adding-the-datepicker-in-events-plugin/#post-5950152)
 * Hi,
 * Thank you very much, it does work with your second piece of code 🙂
 * I used [this tutorial](http://code.tutsplus.com/tutorials/creating-upcoming-events-plugin-in-wordpress-custom-post-type-and-the-dashboard--wp-35404)
   but guess the js. there isn’t working properly.
 * And yes, I will add an if statement to load datepicker only add event page.
 * Thanks again.
 * Guido

Viewing 2 replies - 1 through 2 (of 2 total)

 The topic ‘Adding the datepicker in events plugin’ is closed to new replies.

## Tags

 * [datepicker](https://wordpress.org/support/topic-tag/datepicker/)
 * [event](https://wordpress.org/support/topic-tag/event/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 2 replies
 * 2 participants
 * Last reply from: [Guido](https://wordpress.org/support/users/guido07111975/)
 * Last activity: [11 years, 6 months ago](https://wordpress.org/support/topic/adding-the-datepicker-in-events-plugin/#post-5950152)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
