Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Show the day in the heading on Genesis archives, even if an archive has no posts
<?php
remove_action( 'genesis_archive_title_descriptions', 'genesis_do_archive_headings_headline', 10, 3 );
add_action( 'genesis_archive_title_descriptions', 'custom_do_archive_headings_headline', 10, 3 );
/**
* Adapts archive title to display a date even for days in custom post types that have no posts.
*
* @param string $heading Optional. Archive heading, default is empty string.
* @param string $intro_text Optional. Archive intro text, default is empty string.
* @param string $context Optional. Archive context, default is empty string.
*/
function custom_do_archive_headings_headline( $heading = '', $intro_text = '', $context = '' ) {
if ( is_day() ) {
$date = sprintf(
"%s-%s-%s",
get_query_var( 'year' ),
get_query_var( 'monthnum' ),
get_query_var( 'day' )
);
$date_text = strtotime( $date );
$heading = __( 'Archives for ', 'genesis' ) . date( get_option( 'date_format' ), $date_text );
}
if ( $context && $heading ) {
printf( '<h1 %s>%s</h1>', genesis_attr( 'archive-title' ), esc_html( wp_strip_all_tags( $heading ) ) );
}
}
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.