-
-
Save billerickson/594410d8b8b7040a10752c36e8374434 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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