Instantly share code, notes, and snippets.

@billerickson /functions.php Secret
Last active Jan 4, 2019

Embed
What would you like to do?
<?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