Created
February 18, 2020 19:40
-
-
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
This file contains hidden or 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 | |
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