Support » Plugin: jQuery UI Widgets » Back end loading?

  • Resolved nikolagavric



    I’ve tried to get the datepicker to work in the admin/back end part. But I can’t. The plugin @todo 0.4 says:

    // – Have options to enqueue scripts on front end and back end? Maybe in a future version when admin jQuery styles have been added to core.

    So I guess it’s possible to do pretty easily, but what’s the correct way to do it?

    / Niko

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author David Gwyer


    Hi Niko,

    There are still no core styles in the WordPress admin for jQuery UI even though all the scripts are available in core.

    See this core trac ticket for more information:

    As you can see on the ticket someone has posted styles for the datepicker control to match the admin:

    It depends where you need the datepicker in the admin. If it’s for a theme or plugin options page then you’d probably be better to write your own code to enqueue the datepicker script for that page only and include the custom datepicker CSS I mentioned above.

    You could also do this for all admin pages if that’s what you need.

    Thanks alot for the quick reply David.

    It’s no problem for me to enque it for that page, and yes it’s for a plugin and option page.

    So what I’ve done is just to include this:

    function load_custom_admin_scripts() {
    wp_enqueue_style( 'fib-css', plugins_url() . '/fib-plugin/css/style.css' );
    wp_enqueue_script( 'jquery-validate', plugins_url() . '/fib-plugin/js/jquery.validate.min.js', array(), '1.0.0', true );
    wp_enqueue_script( 'fib-scripts', plugins_url() . '/fib-plugin/js/scripts.js', array(), '1.0.0', true );
    add_action( 'admin_enqueue_scripts', 'load_custom_admin_scripts' );

    And in the your plugins option page I wrote the code:

    jQuery(document).ready(function($) {
    var dateToday = new Date();
    $( "#datepicker" ).datepicker({
    monthNames: ["Januari", "Februari", "Mars", "April", "Maj", "Juni", "Juli", "Augusti", "September", "Oktober", "November", "December"],
    monthNamesShort: ["Jan", "Feb", "Mar", "Apr", "Maj", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dec"],
    dayNames: [ "Söndag", "Måndag", "Tisdag", "Onsdag", "Torsdag", "Fredag", "Lördag" ],
    dayNamesMin: [ "Sö", "Må", "Tis", "Ons", "Tors", "Fre", "Lö" ],
    dateFormat: "yy-mm-dd",
    firstDay: 1,
    minDate: dateToday

    So should this be working if I just add the CSS above? Because right now it’s not, nothing happens when the #datepicker input is being clicked. Or do I have to put the code to initiate somewhere else instead?

    BR / Niko

    Plugin Author David Gwyer


    If it’s for your own plugin then I’d strongly recommend you add the datepicker as part of your own plugin rather than rely on mine. For one thing it will be more portable if your plugin doesn’t require mine to function.

    This might help to point you in the direction of adding the datepicker in the WordPress admin:

    So, add your own datepicker script and enqueue it with the core datepicker script as a dependency. See the above link for how to do this.

    This should be enough to get you started.

    Great, will try to get it to work, thanks again David! 🙂

    Plugin Author David Gwyer


    No problem Niko. Good luck!

    Forgot to mark as resolved, -> done

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Back end loading?’ is closed to new replies.