WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to use the following code

the_time('d. F Y', '<p class="article-date">', '</p>');

to show the date of an article (post) wrapped within <p></p>. I also tried

 echo '<p class="article-date">' .  the_time('d. F Y') . '</p>';

but again the date isn't placed in those tags. What I'm doing wrong? I have a normal foreach and no endforeach and so on.

share|improve this question
I knew that it was wrong, but I wanted to show my efforts. I before had problems with the_date because it was shown only one time and not on each post. – testing May 18 '12 at 16:21
up vote 5 down vote accepted
    <?php the_time() ?>

It helps with separation of concerns and increases readability of code as well as being consistent with WordPress coding standards and the default coding style.

The first method you attempted is completely invalid, the_time() only accepts 1 parameter, the date format. The second method has roots in validity, but the_time() itself is already doing an echo, so by calling it in the middle of the string, you're preempting the outer echo and probably getting the time and an empty p. If you want to use that method you can go with this:

echo '<p>' . get_the_time() . '</p>';

Since get_the_time() returns its value whereas the_time() echos it.


To use the $format parameter correctly:

<?php the_time( 'd. F Y' ) ?>

Note: for a publicly released Theme, it is recommended to use the user-defined date/time format:

<?php the_time( get_option( 'time_format' ) ); ?>

You can also pass the date format to the_time() if you need to output the date for each post in the loop. The the_date() function only outputs the date upon the first occurrence. So, if multiple posts have the same date, the date will only be output once. To get around this limitation, use the_time( $date_format ) instead:

<?php the_time( get_option( 'date_format' ) ); ?>
share|improve this answer
Didn't know that there were coding standards for WP. – testing May 18 '12 at 16:19
Here's a link to the coding standards. – mor7ifer May 18 '12 at 16:49

about your first line of code:

the_time() only uses one parameter.

about your second line of code:

if you want to use 'the_time' in a string concatenation, use get_the_time() :


echo '<p class="article-date">' . get_the_time('d. F Y') . '</p>';
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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