I succeded doing this by copying the needed files to my theme directory.
The files needed are (minimized versions work too):
jquery-xxx.js (xxx=version number)
ui.core.js
ui.datepicker.js
a theme folder for styling
You can also add a localization file to get weekdays and names for your country/language. in my case sweden i add the ui.datepicker-sv.js file.
Then add the following code to where you want to use your datepicker (i added it to a function that echoed a meta-box for posts)
I put all the mentioned files inside a js directory inside my theme.
<!-- css -->
<link type="text/css" href="<?php bloginfo("template_url"); ?>/js/YOUR_SELECTED_THEME/ui.all.css" rel="stylesheet" />
<!-- replace YOUR_SELECTED_THEME with the theme folder you picked -->
<!-- jquery scripts -->
<script type="text/javascript" src="<?php bloginfo("template_url"); ?>/js/jquery-1.3.2.js"></script>
<script type="text/javascript" src="<?php bloginfo("template_url"); ?>/js/ui.core.js"></script>
<script type="text/javascript" src="<?php bloginfo("template_url"); ?>/js/ui.datepicker.js"></script>
<!-- optional localization file -->
<script type="text/javascript" src="<?php bloginfo("template_url"); ?>/js/ui.datepicker-sv.js"></script>
<script type="text/javascript">
var $j = jQuery.noConflict();
$j(function() {
$j("#datepicker").datepicker();
});
</script>
<p><input type="text" id="datepicker" name="date"></p>
I did the same thing but then it conflicted with other jquery-ui functions that were loaded by WordPRess
I am also getting an error when I implement datepicker in the admin area:
this._mouseInit is not a function
in file: load-scripts.php (line 67)
This breaks all of the other js functions loaded by WP. Anyone know of a way around this or a way to fix this?
Any help would be appreciated!
Found help on this thread:
http://wordpress.org/support/topic/including-jquery-breaks-dashboard-javascript?replies=6
I downgraded to 1.7.3 and now it’s not throwing any errors.
Hope this helps someone else.
This worked for me – downloaded the 1.7.3 version of datepicker, then stripped out ui-core from the download js script (I downloaded a package to get the theme) and added my line to initialise the datepicker to it. Added to wp-admin like this:
wp_enqueue_script('datepickerScript', get_bloginfo('template_url') . '/js/jquery-ui-datepicker.min.js', array('jquery','jquery-ui-core'));
Also added smoothness theme like this:
wp_enqueue_style('datepickerStyle', get_bloginfo('template_url') . '/css/smoothness/jquery-ui-smoothness.css');
This assumes you have the relevant CSS and JS in your theme.
Thanks!
downgrading to legacy jquery ui 1.7.3 is the answer when including datepicker to an admin page like posts.php – even for wordpress 3.01.
Hopefully the WP team will update the jquery UI core (just load the full UI package guys) in a very soon release – this is somewhat annoying 🙂