Skip to content

Instantly share code, notes, and snippets.

@Mosharush
Last active July 20, 2017 15:35
Show Gist options
  • Save Mosharush/ddfdbf57a91e8efeeb478b7b2d269dc9 to your computer and use it in GitHub Desktop.
Save Mosharush/ddfdbf57a91e8efeeb478b7b2d269dc9 to your computer and use it in GitHub Desktop.
Post content partial schedule - Wordpress Shortcode
<?php
// Add Shortcode sc_schedule_content - Post content partial schedule
function sc_schedule_content( $atts , $content = null ) {
// Attributes
$atts = shortcode_atts(
array(
'time' => '',
'date' => '',
),
$atts,
'schedule-content'
);
if( is_numeric( $atts['time'] ) && empty( $atts['date'] ) ){
$time = intval( $atts['time'] );
} else{
$time = strtotime( $atts['date'] . ' ' . $atts['time'] );
}
if( get_the_time('U') < $time ){
return $content;
}
}
add_shortcode( 'schedule-content', 'sc_schedule_content' );
@Mosharush
Copy link
Author

Mosharush commented Jul 18, 2017

How to use:

Add the code to your functions.php file on the active theme.
Put shortcode in post content, Text or any content inside tags of shortcode.

Shortcode attributes:

  • date
  • time

Examples:

For unix time

[schedule-content time=1500385179]text text[/schedule-content]

For regular date or/and time:

[schedule-content time="12:25" date="18-07-2017"]text text[/schedule-content]
[schedule-content date="18-07-2017"]text text[/schedule-content]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment