Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am trying to get it so that all of my posts display the date at the beginning of the post content, such that each post begins as:

"August 28 - Lorem ipsum dolor sit amet..."

However, if the code is just:

<?php the_time('F j - '); ?><?php the_content('Read More'); ?>

Then because Wordpress automatically adds p tags around the_content, it ends up displaying with a line break between the date and the rest of the content:

"August 28 -

Lorem ipsum dolor sit amet...

I want to insert the_date inside of the p tags around the_content, so there's isn't that line break. I have been looking around for possible solutions, but I haven't found anything short of removing the p tags entirely, which I don't want to do. Any suggestions?

share|improve this question
    
Try using get_the_content. –  Wyck Aug 28 '11 at 16:47
add comment

1 Answer

You could use the the_content filter, like below (untested). The only thing is, that will add the date pretty much everywhere that your posts show up on your site, unless you add some logic to determine where it's being called from. If that's OK, give it a shot.

add_filter('the_content', 'add_post_date');
function add_post_date($content) {
    global $post;
    return get_the_time('F j - ', $post->ID) . $content;
}
share|improve this answer
1  
A better suggestion would be to use get_the_content and if needed apply_filters. –  Wyck Aug 28 '11 at 16:49
add comment

Your Answer

 
discard

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.