2

I'm in wordpress, I am trying to format the date output. This code use to call the end of the sales promotion:

<?php $thepostid = get_the_ID();
$sale_price_dates_to = ( $date = get_post_meta( $thepostid, '_sale_price_dates_to', true ) ) ? date_i18n( 'M j Y', $date ) : '';
echo '<div class="endsale">' .'<span>'.'Promo end ' . '</span>'.$sale_price_dates_to .'</div>';
?>  

It's output looks like this: JAN 21 2016

I need to style the date and need to give div or span to M, j and Y.

I'm not familiar PHP to get things working.

Can anyone help me?

Thank for any kind of help.

1 Answer 1

2

Just use date_i18n in multiple places with PHP date arguments just for what you need:

if ( $date = get_post_meta( $thepostid, '_sale_price_dates_to', true ) ) {
    $sale_price_dates_to =
        '<span class="m">' . date_i18n( 'M', $date ) . '</span> ' .
        '<span class="d">' . date_i18n( 'j', $date ) . '</span> ' .
        '<span class="y">' . date_i18n( 'Y', $date ) . '</span>';
} else {
    $sale_price_dates_to = '';
}
1
  • Worked. More than to what I need. Thank you @TheDeadMedic
    – Mailmulah
    Commented May 14, 2016 at 21:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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