Plugin Wordpress Insertion Date du Jour via Shortcodes

WRInaute accro
Il y a vraiment besoin d'un plugin pour faire ça ?

PHP:
<?php

function strftime_func( $atts ) {
    $a = shortcode_atts( array(
        'format' => '%A %e %B %Y',
        'locale' => 'fr_FR'
    ), $atts );
   
    $time = empty($a['time']) ? time() : strtotime($a['time']);
   
    $locale = setlocale(LC_TIME, 0);
    setlocale(LC_TIME, $a['locale'] . '.utf8');
    $strftime = strftime($a['format'], $time);
    setlocale(LC_TIME, $locale);
    return $strftime;
}
add_shortcode( 'strftime', 'strftime_func' );

Code:
[strftime]
[strftime time="01-01-2000"]
[strftime format="%d/%m/%Y"]

/!\ pas testé
 
Dernière édition:
Discussions similaires
Haut