Skip to content

Instantly share code, notes, and snippets.

@fugudesign
Last active November 15, 2016 13:23
Show Gist options
  • Save fugudesign/895d1024a06491f39fbb617b9d780a33 to your computer and use it in GitHub Desktop.
Save fugudesign/895d1024a06491f39fbb617b9d780a33 to your computer and use it in GitHub Desktop.
Wordpress archive titles without prefix
/*
* Remove Prefixes from archive titles
*
* @param string $title The title of the archive
* @return string $title The new title for the archive
*/
function my_archive_title( $title ) {
if( is_category() ) {
$title = single_cat_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;
}
add_filter( 'get_the_archive_title', 'my_archive_title' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment