The wp_title-generated <title> in my custom taxonomy archive pages contains the singular taxonomy name with a colon. I can’t figure out where this is coming from (or if it’s default WordPress behavior), and I’d like to remove it. For example, in the archive page for the term ‘Vanilla’ in a taxonomy called ‘Flavors’, the <title> is

Flavor: Vanilla | My Site Name

What I would like the title to be is simply

Vanilla | My site name

The code in header.php is this:

<title><?php wp_title('|', true, 'right'); ?></title>

There’s only one function in functions.php that’s hooked into wp_title, and it looks unrelated to the Taxonomy name. I can’t figure out where this is coming from or how to remove it.

How can I remove this?

(The answer in How to remove parent taxonomy name from the title generated by wp_title()? is not generalizable to this, and I’m guessing there’s a more direct way to do it.)

2 Answers
2

Use wp_title filter to control output

function mamaduka_remove_tax_name( $title, $sep, $seplocation ) {
    if ( is_tax() ) {
        $term_title = single_term_title( '', false );

        // Determines position of separator
        if ( 'right' == $seplocation ) {
            $title = $term_title . " $sep ";
        } else {
            $title = " $sep " . $term_title;
        }
    }

    return $title;
}
add_filter( 'wp_title', 'mamaduka_remove_tax_name', 10, 3 );

Leave a Reply

Your email address will not be published. Required fields are marked *