How to remove “Archives for” text from date archive title?

Original request was:

At the moment it says ‘Archive for june 2016’ but I want it to be just June 2016.

Two ways you can do this. I am showing both methods at below:

Method 1

‘Archive for ‘ is using by the internationalization function (__() ). By “gettext” filter we can remove this translated text. Open your functions.php file and just put this snippets at bottom of the file:

/**
 * How to change the date archive title
 * 
 * @author      Chinmoy Paul
 * @link        http://genesisdeveloper.me
 * @copyright   Copyright (c) 2015 - 2016 Genesis Developer
 * @license     GPL - 2.0+     
 */
add_filter( 'gettext', 'gd_remove_date_archive_title_text', 20, 3 );
function gd_remove_date_archive_title_text( $translated_text, $text, $domain ) {

    if ( is_date() ) {

        switch ( $translated_text ) {

            case 'Archives for ' :

                $translated_text = '';
                break;
                
        }

    }

    return $translated_text;
}

Method 2

genesis/lib/structure/archive.php file have genesis_do_date_archive_title() function which is calling by genesis_before_loop hook. This function is printing the date archive title. At first we need to remove this default hook and create a new one. Again you will write the following scripts in your functions.php file:

remove_action( 'genesis_before_loop', 'genesis_do_date_archive_title' );
add_action( 'genesis_before_loop', 'themeprefix_do_date_archive_title' );
function themeprefix_do_date_archive_title() {

	if ( ! is_date() ) {
		return;
	}

	if ( is_day() ) {
		$headline = get_the_date();
	} elseif ( is_month() ) {
		$headline = single_month_title( ' ', false );
	} elseif ( is_year() ) {
		$headline = get_query_var( 'year' );
	}

	if ( $headline ) {
		printf( '<div %s><h1 %s>%s</h1></div>', genesis_attr( 'date-archive-description' ), genesis_attr( 'archive-title' ), strip_tags( $headline ) );
	}

}

Share This Article

Subscribe Membership Plan ($9.99/mo)

  • Get full access to all premium tutorials
  • Get Support for the posted content
  • Request for specific how-to tutorials
  • Cancel the subscription at anytime

Reader Interactions

Leave A Reply

Your email address will not be published. Required fields are marked *