Title: shortcode for a post&#039;s date published.
Last modified: August 31, 2016

---

# shortcode for a post's date published.

 *  Resolved [cedialogs](https://wordpress.org/support/users/cedialogs/)
 * (@cedialogs)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/shortcode-for-a-posts-date-published/)
 * I have defined several shortcodes in functions.php, all of which work perfectly.
   I want a shortcode for the current post’s date published (post_date) and have
   found many sample code snippets for functions that claim to return post_date,
   but every snippet returns either nothing or DateTime.Now. Here are some of my
   attempts at making a function that will retrieve post_date:
 * function date_created( ) {
    return ‘Posted: ‘ . $post->post_date; /* return ‘
   Posted: ‘ . mysql2date(‘M d, Y G:i’, get_post($post_ID)->post_date); */ /* return‘
   Posted: ‘ . mysql2date(‘M d, Y G:i’, $post->post_date); */ } add_shortcode( ‘
   created’, ‘date_created’);
 * I am presuming that the variable $post_ID is previously defined and is not null.
   If it is undefined, I have no idea how to properly define it.

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/shortcode-for-a-posts-date-published/#post-7198686)
 * try to add:
 *     ```
       global $post;
       ```
   
 * as the first line of the shortcode.
 *  Thread Starter [cedialogs](https://wordpress.org/support/users/cedialogs/)
 * (@cedialogs)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/shortcode-for-a-posts-date-published/#post-7198820)
 * Thanks, Michael. I was given an alternative approach that is rather klunky but
   does seem to work.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘shortcode for a post's date published.’ is closed to new replies.

## Tags

 * [date published](https://wordpress.org/support/topic-tag/date-published/)
 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [cedialogs](https://wordpress.org/support/users/cedialogs/)
 * Last activity: [10 years, 1 month ago](https://wordpress.org/support/topic/shortcode-for-a-posts-date-published/#post-7198820)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
