0

I want to display dates in Hindi format like

jan 10

using get_the_date() function. What I have tried so far:

echo get_the_date(_e('F j'));

which outputs:

F jJanuary 10, 2017.
0

Try below code.

echo get_the_date(__('M d'));

Output:

Feb 09

echo get_the_date(__('M d, Y'));

Output:

Feb 09, 2017

|improve this answer|||||
  • It doesn't work in hindi. It output like in hindi : ???? 23 – shubham shah Feb 16 '17 at 11:19
  • It shows in hindi if you are selected site language hindi (Dashboard >> Settings >> General) – AddWeb Solution Pvt Ltd Feb 16 '17 at 12:50
  • 1
    But I want both english and hindi on my site when user click on language translate button.. check url : competitionmantra.com – shubham shah Feb 17 '17 at 5:40
0

Old question, but no answer accepted, so here goes..

You get weird output, because _e just prints "F j" literally and isn't passing it to the function. Hence you get the raw format followed by the default date format.

However, you don't need to use any translation function, because get_the_date() handles it all. Just do:

<?php echo get_the_date('F j'); ?>

Translations of the months are in the WordPress core translation files. If you have a translation of "October" in Hindi and have your site language set to hi_IN it will display the translated date.

See this recent, similar question with some more detail on the date_format option.

|improve this answer|||||
  • it doesnt work for spanish – ValRob Feb 19 '19 at 15:43
  • It works for all languages, equally. – Tim Feb 19 '19 at 17:50
0

The WordPress date_i18n function comes in handy for none english sites and when using multiple languages/locales. You can find more info on the WordPress code reference here.

In your case, I would try:

<?php echo date_i18n( 'F j', strtotime( get_the_date() ) ); ?>

Hope this helps.

|improve this answer|||||
0

You can try this method:

https://developer.wordpress.org/reference/functions/switch_to_locale/

It allows you to changed the frontend language

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.