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!

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]');
| improve this answer | |
  • Yes! You my friend are amazing. I couldn't figure out how to use the strtotime code and where to put it. Thank you! – Coleman Smith Sep 25 '19 at 19:10
  • your welcome :-) – Chetan Vaghela Sep 26 '19 at 4:34

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.