WP Shortcode to show post date and categories

I am trying to create a shortcode to display a post’s date and category. I have cobbled this together and I can get the category to show properly but not the date. What am I doing wrong?

Here is a link to the sample page: http://testdoug.com/phr-test/test-post-1/

//[categories-list]
function insertcats( $atts, $content = null ) {
    global $post;
    $categories = get_the_category_list( ', ', '', $post->ID );
    $my_date = get_the_date('echo $date_style;', FALSE);
    return '<div class="vcex-blog-entry-date"' . $my_date . '<div class="blog-category">' . $categories . '</div></div>';
}

add_shortcode("insertcats", "insertcats");

Related posts

1 comment

  1. your markup is a little wrong and you’re missing a closing tag.

    the correct format should be:

    function insertcats( $atts, $content = null ) {
        global $post;
        $date_style = 'd M Y';//Your Format;
        $categories = get_the_category_list( ', ', '', $post->ID );
        $my_date = get_the_date($date_style, FALSE);
        return '<div class="vcex-blog-entry-date">' . $my_date . '<div class="blog-category">' . $categories . '</div></div>';
    }
    
    add_shortcode("insertcats", "insertcats");
    

Comments are closed.