Skip to content

Instantly share code, notes, and snippets.

@abelsaad
Created July 5, 2021 12:46
Show Gist options
  • Save abelsaad/d0a28861f909b89ab4f1dccbc10a67b1 to your computer and use it in GitHub Desktop.
Save abelsaad/d0a28861f909b89ab4f1dccbc10a67b1 to your computer and use it in GitHub Desktop.
How to remove “Archive:”, “Category:” etc. pre-title inserts in Archive Titles
<?php
add_filter( 'get_the_archive_title', 'my_theme_archive_title' );
/**
* Remove archive labels.
*
* @param string $title Current archive title to be displayed.
* @return string Modified archive title to be displayed.
*/
function my_theme_archive_title( $title ) {
if ( is_category() ) {
$title = single_cat_title( '', false );
} elseif ( is_tag() ) {
$title = single_tag_title( '', false );
} elseif ( is_author() ) {
$title = '<span class="vcard">' . get_the_author() . '</span>';
} elseif ( is_post_type_archive() ) {
$title = post_type_archive_title( '', false );
} elseif ( is_tax() ) {
$title = single_term_title( '', false );
}
return $title;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment