admin管理员组文章数量:1279186
I am using the below code to display current date in php using shortcodes for Indian time zones:
add_shortcode( 'current_date', 'mth_footer_date2' );
function mth_footer_date2() {
ob_start();
date_default_timezone_set("Asia/Kolkata");
echo gmdate("jS F Y");
return ob_get_clean();
}
We need to add [current_date]
Shortcode to display current date. This code is displaying date but I think, this is not in Indian Timezone. Please provide me such codes to display time in Indian Timezone. I want Date in following format, Sunday, 24th October, 2021.
Also provide ways to show tomorrow date in same format.
I am using the below code to display current date in php using shortcodes for Indian time zones:
add_shortcode( 'current_date', 'mth_footer_date2' );
function mth_footer_date2() {
ob_start();
date_default_timezone_set("Asia/Kolkata");
echo gmdate("jS F Y");
return ob_get_clean();
}
We need to add [current_date]
Shortcode to display current date. This code is displaying date but I think, this is not in Indian Timezone. Please provide me such codes to display time in Indian Timezone. I want Date in following format, Sunday, 24th October, 2021.
Also provide ways to show tomorrow date in same format.
Share Improve this question edited Oct 24, 2021 at 14:20 Buttered_Toast 2,8191 gold badge8 silver badges21 bronze badges asked Oct 24, 2021 at 13:04 Amresh MishraAmresh Mishra 32 bronze badges 1 |1 Answer
Reset to default 0You need to use date()
in place of gmdate()
, which returns the date/time for GMT.
To get the output you want, change the code to:
echo date('l, jS F, Y');
For displaying tomorrow's date, use the following code accordingly:
$timestamp = strtotime('tomorrow');
echo date('l, jS F, Y', $timestamp);
本文标签: Display Current Date using shortcode
版权声明:本文标题:Display Current Date using shortcode 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741253946a2366311.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
ob_start()
/echo
/ob_get_clean()
, you can simplyreturn date( "jS F Y" );
. Note that, per the docs, shortcode callbacks should never output content directly, but should alwaysreturn
the content. – Pat J Commented Oct 24, 2021 at 15:48