47

I have the following code in my theme's archive.php:

<?php the_archive_title( '<h1 class="page-title">', '</h1>' ); ?>

This gives me titles like "Category: Russia", "Tag: America", "Author: John".

I would like to remove the "Category:", "Tag:" and "Author:" part and just display the category, tag and author names.

Does anyone know how to accomplish this?

Thank you.

69

You can extend the get_the_archive_title filter which I've mentioned in this answer

add_filter( 'get_the_archive_title', function ($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>' ;

        }

    return $title;

});
  • 2
    That works! Thanks, Pieter! In case less tech-savy users are looking for the same solution: You add Pieter's code to your functions.php file and that's it! – Nick Feb 27 '15 at 21:05
  • Do this in a child theme so your changes won't get lost upon a theme update. – Jürgen Paul Aug 19 '16 at 7:01
  • 1
    This works pretty well, but it's missing cases for archives and custom taxonomies. – JacobTheDev Nov 23 '16 at 16:57
  • See Ben Gillbanks' solution to all post type archives and taxonomies. – Dan Knauss Jan 27 '18 at 5:54
24

Use function single_term_title()

  • You can do things many ways in WP, but I always opted for the simplest solutions. Thanks Timo. – f055 Jan 11 '18 at 14:22
  • Well that just doesn't work for all archives that aren't terms. So in my opinion not a very good solution. – GDY Apr 5 at 7:13
9

For CPT title Without word: ‘Archive’:

If you are building custom archive template for a CPT, and want to output just the title of the CPT with no extra word like “Archive” use following function instead:

echo post_type_archive_title( '', false );

From developer.wordpress.org

5

I feel like this is over simplifying things, but this is what I did...

<h1><?php echo str_replace("Archives: ", "", get_the_archive_title()); ?></h1>
  • 1
    this wouldn't work for an non-english website. – Maxwell s.c Nov 9 '18 at 15:50
2

echo '<h1 class="page-title">' . single_cat_title( '', false ) . '</h1>'; in taxonomy-category.php outside public of theme.

1

I would use a filter and put it in a file functions.php

add_filter( 'get_the_archive_title', 'replaceCategoryName'); 
   function replaceCategoryName ($title) {

   $title =  single_cat_title( '', false );
   return $title; 
}
-2

You can use the following to just have only the title without the prefix

single_cat_title();
  • 2
    While true, this has been suggested before in other answers. – Nicolai Feb 27 '18 at 18:52
-4

directory: wp-includes

file: general-template.php

find function: get_the_archive_title() change:

if ( is_category() ) {
        $title = sprintf( __( 'Category: %s' ), single_cat_title( '', false ) );
    } elseif ( is_tag() ) {
        $title = sprintf( __( 'Tag: %s' ), single_tag_title( '', false ) );
    } elseif ( is_author() ) {
        $title = sprintf( __( 'Autor: %s' ), '<span class="vcard">' . get_the_author() . '</span>' );
    }

to:

if ( is_category() ) {
        $title = sprintf( __( '%s' ), single_cat_title( '', false ) );
    } elseif ( is_tag() ) {
        $title = sprintf( __( '%s' ), single_tag_title( '', false ) );
    } elseif ( is_author() ) {
        $title = sprintf( __( '%s' ), '<span class="vcard">' . get_the_author() . '</span>' );
    }//if you want to remove or just change text if you need to
  • 3
    Err, are you really suggesting hacking the core here? – cjbj Sep 6 '16 at 13:42
  • 3
    This is a very, very bad idea. You cannot update now without creating a separate branch. – fuxia Sep 6 '16 at 13:57
  • Sory if I break roles I give a word for that, but this is just another solution nothing malicious. So, you said that I hack my own site or I cant share code from core files? – Dragan Nikolic Sep 6 '16 at 17:36
  • Well, it's your website and you may edit whatever you want - even the core files. However, the web will break if you update your Wordpress... – Raccoon Sep 22 '16 at 0:08

protected by Community Jul 16 '18 at 19:14

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.