Last active
January 4, 2016 01:28
-
-
Save sylwit/8548256 to your computer and use it in GitHub Desktop.
Shortcode wordpress permettant d'afficher du contenu en fonction de la date du jour Ex : [evollia_visible start_date="2014-01-01" end_date="2014-01-31"] contenu [/evollia_visible]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function evollia_visible_shortcode( $atts, $content = null ) { | |
extract( shortcode_atts( array( | |
'start_date' => '', | |
'end_date' => '', | |
), $atts ) ); | |
$today = new DateTime( date('Y-m-d') ); | |
$display = true; | |
if ($start_date){ | |
$start_date = new DateTime($start_date); | |
if ( $today < $start_date ) $display = false; | |
} | |
if ($end_date){ | |
$end_date = new DateTime($end_date); | |
if ( $today > $end_date ) $display = false; | |
} | |
if ( !$display) $content = ''; | |
return do_shortcode($content); | |
} | |
add_shortcode( 'evollia_visible', 'evollia_visible_shortcode' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment