Last active
August 23, 2018 19:39
-
-
Save crondeau/014d5587e416dc1001dc to your computer and use it in GitHub Desktop.
get_the_archive_title() filter
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
/* | |
* Remove Prefixes from archive title | |
*/ | |
add_filter( 'get_the_archive_title', function ( $title ) { | |
if( is_category() ) { | |
$title = single_cat_title( '', false ); | |
} | |
elseif ( is_tag() ) { | |
$title = single_tag_title( '', false ); | |
} | |
elseif( is_tax() ) { | |
$tax = get_taxonomy( get_queried_object()->taxonomy ); | |
/* translators: 1: Taxonomy singular name, 2: Current taxonomy term */ | |
$title = sprintf( __( '%2$s' ), $tax->labels->singular_name, single_term_title( '', false ) ); | |
} | |
elseif ( is_year() ) { | |
$title = sprintf( __( '%s' ), get_the_date( _x( 'Y', 'yearly archives date format' ) ) ); | |
} | |
elseif ( is_month() ) { | |
$title = sprintf( __( '%s' ), get_the_date( _x( 'F Y', 'monthly archives date format' ) ) ); | |
} | |
return $title; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment