简体   繁体   中英

How do I format a post's date using shortcodes in Wordpress?

Can anybody help with this please? I'm using this shortcode to display a post's date below the title [mm-insert-date] It works fine, but is displaying as "2014-02-01 01:24:27" I would like it to read something like "Feb 2 2014" and lose the clock time. I've tried quite a few things from searching etc but nothing's working for me.

Any help greatly appreciated!

Here's the function from the themes function.php file

function mm_insert_date_func($atts) {
   // Insert the post date, with optional before and after strings.
   // [mm-insert-date before='<h3>' after='</h3>']
   global $post;
   extract(shortcode_atts(array('before' => '', 'after' => '' ), $atts));  

   $output = "{$before}{$post->post_date}{$after}";      


   return $output;
}

add_shortcode('mm-insert-date', 'mm_insert_date_func');

我有一个可行的解决方案:

$output = $before . date('M j Y', strtotime($post->post_date)) . $after;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM