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

php - Changing Date Format on Custom Meta Data wshortcode call

programmeradmin2浏览0评论

I am currently pulling a date from a users meta and making it so I can input a shortcode and it will show that date in certain places. I have the following code written and it works great!

function delivery_date( $atts ) {

global $current_user, $user_login;
      get_currentuserinfo();
add_filter('widget_text', 'do_shortcode');
if ($user_login) 
return $current_user->delivery_date ;

}

add_shortcode( 'delivery_date', 'delivery_date' );

Now, my problem is that the date is showing up at Y-m-d (2019-09-25) but I want it to show up as d-m-Y (09-25-2019). What is the best way to do this? What do I need to add to my code and where? All help is much appreciated! Thank you!

I am currently pulling a date from a users meta and making it so I can input a shortcode and it will show that date in certain places. I have the following code written and it works great!

function delivery_date( $atts ) {

global $current_user, $user_login;
      get_currentuserinfo();
add_filter('widget_text', 'do_shortcode');
if ($user_login) 
return $current_user->delivery_date ;

}

add_shortcode( 'delivery_date', 'delivery_date' );

Now, my problem is that the date is showing up at Y-m-d (2019-09-25) but I want it to show up as d-m-Y (09-25-2019). What is the best way to do this? What do I need to add to my code and where? All help is much appreciated! Thank you!

Share Improve this question asked Sep 25, 2019 at 9:15 Coleman SmithColeman Smith 31 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

Try with change line to date('d-m-Y',strtotime($current_user->delivery_date)) ;

function delivery_date( $atts ) {
    global $current_user, $user_login;
    get_currentuserinfo();
    add_filter('widget_text', 'do_shortcode');
    if ($user_login) 
        return date('d-m-Y',strtotime($current_user->delivery_date)) ;

}
add_shortcode( 'delivery_date', 'delivery_date' );

echo do_shortcode('[delivery_date]');
发布评论

评论列表(0)

  1. 暂无评论