最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

css - Inbuilt style for jquery-ui-datepicker

programmeradmin2浏览0评论

I want to use the datepicker that gets bundled with WordPress on the front end of a website. I enqueued jquery-ui-datepicker but the datepicker isn't styled(no js error in console). Is there a corresponding wp_enqueue_style for that?

I used this code in functions.php

function rr_scripts() {
  wp_enqueue_script( 'jquery' );
  wp_enqueue_script( 'jquery-ui-datepicker', array( 'jquery' ) );

  wp_register_style( 'bootstrap_css', get_template_directory_uri() . '/assets/css/bootstrap.min.css' );
  wp_enqueue_style( 'bootstrap_css' ); # I'm using Twitter Bootstrap as CSS(if it matters)
}
add_action( 'wp_enqueue_scripts', 'rr_scripts' );

I want to use the datepicker that gets bundled with WordPress on the front end of a website. I enqueued jquery-ui-datepicker but the datepicker isn't styled(no js error in console). Is there a corresponding wp_enqueue_style for that?

I used this code in functions.php

function rr_scripts() {
  wp_enqueue_script( 'jquery' );
  wp_enqueue_script( 'jquery-ui-datepicker', array( 'jquery' ) );

  wp_register_style( 'bootstrap_css', get_template_directory_uri() . '/assets/css/bootstrap.min.css' );
  wp_enqueue_style( 'bootstrap_css' ); # I'm using Twitter Bootstrap as CSS(if it matters)
}
add_action( 'wp_enqueue_scripts', 'rr_scripts' );
Share Improve this question edited Jan 27, 2013 at 15:10 s_ha_dum 65.6k13 gold badges84 silver badges174 bronze badges asked Jan 27, 2013 at 13:44 RRikeshRRikesh 5,6554 gold badges31 silver badges45 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 22

As far as I know, there is not style for datepicker. You have to register your own. The code then will be:

function rr_scripts() {
  wp_enqueue_script( 'jquery' );
  wp_enqueue_script( 'jquery-ui-datepicker', array( 'jquery' ) );

  wp_register_style( 'bootstrap_css', get_template_directory_uri() . '/assets/css/bootstrap.min.css' );
  wp_enqueue_style( 'bootstrap_css' ); // I'm using Twitter Bootstrap as CSS(if it matters)

  wp_register_style('jquery-ui', 'http://ajax.googleapis/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css');
  wp_enqueue_style( 'jquery-ui' );   
}

add_action( 'wp_enqueue_scripts', 'rr_scripts' );

To load script & style, add the following code to your theme's functions.php file.

function add_e2_date_picker(){
//jQuery UI date picker file
wp_enqueue_script('jquery-ui-datepicker');
//jQuery UI theme css file
wp_enqueue_style('e2b-admin-ui-css','http://ajax.googleapis/ajax/libs/jqueryui/1.9.0/themes/base/jquery-ui.css',false,"1.9.0",false);
}
add_action('wp_enqueue_scripts', 'add_e2_date_picker'); 

Script for back-end use:

function add_e2_date_picker(){
//jQuery UI date picker file
wp_enqueue_script('jquery-ui-datepicker');
//jQuery UI theme css file
wp_enqueue_style('e2b-admin-ui-css','http://ajax.googleapis/ajax/libs/jqueryui/1.9.0/themes/base/jquery-ui.css',false,"1.9.0",false);
}
add_action('admin_enqueue_scripts', 'add_e2_date_picker'); 

I have to hook into options-general.php to display on Settings->Date Picker. Just put this code again in functions.php file below previous code.

function register_datepiker_submenu() {
    add_submenu_page( 'options-general.php', 'Date Picker', 'Date Picker', 'manage_options', 'date-picker', 'datepiker_submenu_callback' );
}

function datepiker_submenu_callback() { ?>

    <div class="wrap">

    <input type="text" class="datepicker" name="datepicker" value=""/>

    </div>

    <script>
    jQuery(function() {
        jQuery( ".datepicker" ).datepicker({
            dateFormat : "dd-mm-yy"
        });
    });
    </script> 

<?php }
add_action('admin_menu', 'register_datepiker_submenu');

?>

Please see more details on Add a jQuery Date Picker to WordPress Theme or Plugin

发布评论

评论列表(0)

  1. 暂无评论