1

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?

1
  • Try using get_the_content.
    – Wyck
    Aug 28, 2011 at 16:47

1 Answer 1

1

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;
}
1
  • 1
    A better suggestion would be to use get_the_content and if needed apply_filters.
    – Wyck
    Aug 28, 2011 at 16:49

Your Answer

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

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