shortcode for a post's 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.
- The topic ‘shortcode for a post's date published.’ is closed to new replies.