Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yumyo/8044cde315ca12100f92ca0d489a9211 to your computer and use it in GitHub Desktop.
Save yumyo/8044cde315ca12100f92ca0d489a9211 to your computer and use it in GitHub Desktop.
WordPress Archive Title conditionals to correct display
<?php
function archive_title() {
//Conditionals to Title Display in WordPress Archive Templates
if( is_archive() ) {
$queried_object = get_queried_object();
if( is_tag() ) {
$slug = $queried_object ? $queried_object->slug : ' ' ;
return ucfirst( $queried_object->name );
} else if( is_tax() ){
$slug = $queried_object ? $queried_object->slug : ' ' ;
return ucfirst( $queried_object->name );
} else {
$slug = $queried_object ? $queried_object->rewrite['slug'] : ' ' ;
return $queried_object->labels->name;
}
//Fallback if there's no archive matching the conditions
return 'Archives';
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment