Last active
November 15, 2016 13:23
-
-
Save fugudesign/895d1024a06491f39fbb617b9d780a33 to your computer and use it in GitHub Desktop.
Wordpress archive titles without prefix
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 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