Skip to content

Instantly share code, notes, and snippets.

@billerickson
Created June 23, 2019 16:22
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/594410d8b8b7040a10752c36e8374434 to your computer and use it in GitHub Desktop.
Save billerickson/594410d8b8b7040a10752c36e8374434 to your computer and use it in GitHub Desktop.
<?php
/**
* Display Posts - Include Event Date
*
*/
function be_dps_include_event_date( $output, $original_atts, $image, $title, $date, $excerpt, $inner_wrapper, $content, $class, $author, $category_display_text ) {
if( empty( $original_atts['include_event_date'] ) || false === filter_var( $original_atts['include_event_date'], FILTER_VALIDATE_BOOLEAN ) )
return $output;
$key = 'be_event_start';
$event_date = get_post_meta( get_the_ID(), $key, true );
if( empty( $event_date ) )
return $output;
// Convert to formatted date.
// See: https://wordpress.org/support/article/formatting-date-and-time
$event_date = date( 'F j, Y', $event_date );
// Add span around it for styling
$event_date = '<span class="event-date">' . $event_date . '</span>';
// Insert it into the output wherever you'd like it
$output = '<' . $inner_wrapper . ' class="' . implode( ' ', $class ) . '">' . $image . $title . $event_date . $date . $author . $category_display_text . $excerpt . $content . '</' . $inner_wrapper . '>';
return $output;
}
add_filter( 'display_posts_shortcode_output', 'be_dps_include_event_date', 10, 11 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment