0

I want to make a custom entry_date function based on the one found in twenty-thirteen. I just want to have the day, the month and the year in separate <span>s I don't understand why what I want to achieve will not work. The date is printed but not inside the <a href=""> tag.

What am I doing wrong?

My code is:

$date = sprintf( '<span class="date"><a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s"><span class="date--day">%4$s</span><span class="date--month">%5$s</span><span class="date--year">%6$s</span></time></a></span>',
    esc_url( get_permalink() ),
    esc_attr( sprintf( __( 'Permalink to %s', 'lyod' ), the_title_attribute( 'echo=0' ) ) ),
    esc_attr( get_the_date( 'c' ) ),
    esc_attr( the_time(d)),
    esc_attr( the_time(M)),
    esc_attr( the_time(Y))
);

For the record, here is Twenty-Thirteen function:

$date = sprintf( '<span class="date"><a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s">%4$s</time></a></span>',
    esc_url( get_permalink() ),
    esc_attr( sprintf( __( 'Permalink to %s', 'twentythirteen' ), the_title_attribute( 'echo=0' ) ) ),
    esc_attr( get_the_date( 'c' ) ),
    esc_html( sprintf( $format_prefix, get_post_format_string( get_post_format() ), get_the_date() ) )
);

Thank you in advance for the help!

1 Answer 1

1

You should be using get_the_date, rather than the_time (which will just echo the value). And always quote string arguments.

$date = sprintf( '<span class="date"><a href="%s" title="%s" rel="bookmark"><time class="entry-date" datetime="%s"><span class="date--day">%s</span><span class="date--month">%s</span><span class="date--year">%s</span></time></a></span>',
    esc_url( get_permalink() ),
    esc_attr( sprintf( __( 'Permalink to %s', 'lyod' ), the_title_attribute( 'echo=0' ) ) ),
    esc_attr( get_the_date( 'c' ) ),
    esc_attr( get_the_date( 'd' ) ),
    esc_attr( get_the_date( 'M' ) ),
    esc_attr( get_the_date( 'Y' ) )
);
0

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.