Skip to content

Instantly share code, notes, and snippets.

@billerickson

billerickson/functions.php Secret

Created Jun 23, 2019
Embed
What would you like to do?
<?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
You can’t perform that action at this time.