Skip to content

Instantly share code, notes, and snippets.

@sylwit
Last active January 4, 2016 01:28
Show Gist options
  • Save sylwit/8548256 to your computer and use it in GitHub Desktop.
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]
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