Skip to content

Instantly share code, notes, and snippets.

@filipvanreeth
Last active November 26, 2016 17:08
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 filipvanreeth/a48a52d3f59494f609fd45a6cddfa476 to your computer and use it in GitHub Desktop.
Save filipvanreeth/a48a52d3f59494f609fd45a6cddfa476 to your computer and use it in GitHub Desktop.
function wb_get_title( $before = '<h1>', $after = '</h1>' ) {
$title = NULL;
if ( is_page() || is_singular() || is_single() ) {
$title = get_the_title();
} elseif ( is_archive() ) {
$title = $category_name = single_cat_title( '', false );
} elseif ( is_post_type_archive() ) {
$obj = get_queried_object();
$title = $obj->labels->name;
} elseif ( is_tax() ) {
$title = $wp_query->obj->name;
} else {
$title = get_the_title();
}
if ( $title ) {
echo $before . $title . $after;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment