Skip to content

Instantly share code, notes, and snippets.

@allysonsouza
Last active June 6, 2017 09:49
Show Gist options
  • Save allysonsouza/572ebf20a356b063473a to your computer and use it in GitHub Desktop.
Save allysonsouza/572ebf20a356b063473a 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