How to remove “Taxonomy name:” from wp_title

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

Read More

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.)

Related posts

Leave a Reply

2 comments

  1. 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 );
    
  2. I’d recommend you use a SEO plugin to take control of all of your titles. WordPress SEO by Yoast is very good.

    Or you could add a filter to wp_title to change the output.

    <?php 
    add_filter( 'wp_title', 'wpse29020_fix_title', 10, 3 );
    function wpse29020_fix_title( $title, $sep, $seplocation )
    {
        // If this isn't our flavors taxonomy, just return the title
        if( ! is_tax( 'flavors' ) ) return $title;
    
        // Get the term
        $obj = get_queried_object();
    
        // Get the terms name
        $name = sanitize_term_field( 'name', $obj->name, $obj->term_id, 'flavors', 'display' );
    
        // construct the title
        $title = $name . " $sep " . bloginfo( 'name' );
        return $title;
    }