php - Changing Date Format on Custom Meta Data wshortcode call

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 c

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]');

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745131254a4612983.html

相关推荐

  • php - Changing Date Format on Custom Meta Data wshortcode call

    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 c

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信