Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@billerickson
Last active January 4, 2019 05:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billerickson/4fb121ce8e025097da364c25adc70fe6 to your computer and use it in GitHub Desktop.
Save billerickson/4fb121ce8e025097da364c25adc70fe6 to your computer and use it in GitHub Desktop.
<?php
/**
* Add Time to Display Posts Shortcode
* @link https://displayposts.com/2019/01/04/display-time-after-post-date/
*
*/
function be_display_posts_time( $output, $original_atts, $image, $title, $date, $excerpt, $inner_wrapper, $content, $class, $author, $category_display_text ) {
// Only run our code if include_time is set
if( empty( $original_atts['include_time'] ) )
return $output;
$time = ' at ' . get_the_time( 'g:i a' );
// Now let's rebuild the output and add the $time to it
$output = '<' . $inner_wrapper . ' class="' . implode( ' ', $class ) . '">' . $image . $title . $date . $time . $author . $category_display_text . $excerpt . $content . '</' . $inner_wrapper . '>';
// Finally we'll return the modified output
return $output;
}
add_filter( 'display_posts_shortcode_output', 'be_display_posts_time', 10, 11 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment