Skip to content

Instantly share code, notes, and snippets.

@nickcernis
Created February 18, 2020 19:40
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 nickcernis/35c828932645d11f3859435c6cbc4f2c to your computer and use it in GitHub Desktop.
Save nickcernis/35c828932645d11f3859435c6cbc4f2c to your computer and use it in GitHub Desktop.
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