Change date picker output

Home Forums Calendar Products Events Calendar PRO Change date picker output

Viewing 15 posts - 1 through 15 (of 17 total)
  • Author
    Posts
  • #1353802
    Palmtree
    Participant

    Hello codemaster,

    I would like to change the way the month display inside date picker calendar which is popup (overlay) option when you filter the event date.
    I think by default it outputs like “Sep 2017” when the date picker is displaying September calendar.

    Currently it says “9月 2017”. It is in Japanese by the way.. And this is automatic (perhaps naturally output based on the language of the wordpress or OS I’m using) so far I didn’t tough any code for this output.

    I want to change this to 2017年9月. You notice that the “9 (month)” goes behind the year 2017 and I want to put “年” text right after 2017. Is it something can be done in translation file or….?

    Thank you for your support.
    Palmtree

    #1353804
    Palmtree
    Participant

    This reply is private.

    #1354547
    Andras
    Keymaster

    Hello Palmtree,

    Thanks for getting in touch!

    For the datepicker we are using an external library and the date settings in WordPress or The Events Calendar have no effect on this. It looks like not even the browser language has an effect on this, so might be the Operating System language and date format setting as a default.

    I will try to check if it can be influenced by some code. Please hang in there while I do this, it might take some time.

    Thanks,
    Andras

    #1354738
    Palmtree
    Participant

    András thank you for looking at this. I look forward to hearing from you.

    #1356475
    Barry
    Member

    Hi Palmtree,

    Perhaps this snippet will help you:

    add_action( 'wp_footer', function() {
    echo <<<HTML
    <script type="text/javascript">
    if (
    'function' === typeof jQuery
    && 'function' === typeof jQuery.fn.bootstrapDatepicker
    ) {
    // 1) In this example we're adjusting the jp (Japanese) property,
    // to modify the English equivalent we'd access en instead.
    //
    // 2) The format in this example will result in the year then the
    // full month, but all formats as described below are accepted:
    // https://bootstrap-datepicker.readthedocs.io/en/latest/options.html#format
    jQuery.fn.bootstrapDatepicker.dates.jp['titleFormat'] = 'yyyy MM';
    }
    </script>
    HTML;
    }, 1000 );

    This could be added either to a custom plugin (preferred) or else to your theme’s functions.php file.

    Please note that you will probably need to tweak it to get the format you desire, as per the comments in the code itself 🙂

    #1356478
    Barry
    Member

    …and just for the benefit of other users reviewing this topic, I’d emphasize again the need to read the comments in the code. If you are running an English language site, for example, the above code will probably result in an error unless you swap out the reference to jp with en (and so on for other languages).

    #1356522
    Palmtree
    Participant

    Thank you Barry!

    I have put following code but the screen went complete white…

    add_action( 'wp_footer', function() {
        echo '
            <script type="text/javascript">
                if ( 
                    'function' === typeof jQuery
                    && 'function' === typeof jQuery.fn.bootstrapDatepicker
                ) {
                    jQuery.fn.bootstrapDatepicker.dates.jp['titleFormat'] = 'yyyy年m月';
                }
            </script>';
    }, 1000 );

    Am I missing something?

    #1356644
    Andras
    Keymaster

    Hi Palmtree,

    I tested Barry’s code and it works. I see you did some adjustment to it and likely that is the cause.

    This is a mixed code of php and javascript, so that is why some things might look unusual. Make sure that you copy the code Barry provided as it is.

    Specifically the beginning:

    echo <<<HTML

    and the end

    </script>
    HTML;
    }, 1000 );

    Does that do the trick?

    A.

    #1356656
    Palmtree
    Participant

    Hi András,

    You are right, I have modified a bit. Now I went back and used the original code shown below… And still doesn’t work. I pasted into theme’s functions.php

    Is there something I am still missing here? I appreciate if you could take a look at my code.

    add_action( 'wp_footer', function() {
        echo <<<HTML
            <script type="text/javascript">
                if ( 
                    'function' === typeof jQuery
                    && 'function' === typeof jQuery.fn.bootstrapDatepicker
                ) {
                    jQuery.fn.bootstrapDatepicker.dates.jp['titleFormat'] = 'yyyy年m月';
                }
            </script>
    HTML;        
    }, 1000 );
    #1356796
    Andras
    Keymaster

    Hi,

    There are a couple of extra spaces after the closing HTML. You can see it when you select the code. I pointed it out on this screenshot.

    Once you remove those spaces it should work.

    A.

    #1357250
    Palmtree
    Participant

    This reply is private.

    • This reply was modified 8 years, 7 months ago by Palmtree.
    #1357612
    Andras
    Keymaster

    Hello Palmtree,

    No worries at all!

    The issue might be that in line 207 you have used so called curly quotes (”) instead of the straight ones (“). That can cause confusion and errors.

    Instead of putting it in your functions.php file you can have it as a separate plugin.

    I quickly created the plugin version of it for you, you can download it from here:

    https://gist.github.com/andrasguseo/08b9f3cff12facd93469c4dab212252d

    On the top right of the page you will see a ‘Download ZIP’ button. Click on that and save it. Then unpack and copy only the php file on your server into the wp-content/plugins folder just like that.

    Don’t forget to modify the settings in the code to Japanese and your date format.

    Then in your admin dashboard go to your plugins and activate it. On the front-end you should see the change.

    Let me know how this works out.

    Cheers,
    Andras

    #1357613
    Andras
    Keymaster

    In case you use the plugin, don’t forget to remove the code from your functions.php. 😉

    #1357665
    Palmtree
    Participant

    This reply is private.

    #1358159
    Andras
    Keymaster

    This reply is private.

Viewing 15 posts - 1 through 15 (of 17 total)
  • The topic ‘Change date picker output’ is closed to new replies.