How to show date with previous post link in WordPress

When viewing a post, I want to show the date of the previous post underneath the previous/next post links but $post is not available in previous_post_link().

How can I carry forward the post date from the previous post as well as get the date for the next link?

Related posts

Leave a Reply

1 comment

  1. Did a bit of searching on the web, but no result. Then I opened the file wp-include/link-tempalte.php.

    On line 1327 you will find next_post_link which calls adjacent_post_link function.
    This function again calls get_adjacent_post function to retrieve previous post data.

    Looking at the source, you should be able to do the following:

      $in_same_cat = false; 
      $excluded_categories = '';
      $previous = true;
      $post = get_adjacent_post($in_same_cat, $excluded_categories, $previous);
      echo $post->post_date;
    

    This is not tested, but I think it hould work.