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.

  • 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
    <?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' ) ); ?>

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

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.