Site logo

Archived topic

Editing title tag for Google indexing

10 replies · Started by Dave on December 10, 2018

Viewing posts 1–11 of 11

I don't know if GP sets this value or something in WP. Right now my per post <title> tag displays POST NAME - SITE NAME which is what shows in browser tabs and Google searches. I want to drop the site name. How would that be handled? Thanks!

That’s something of a sledgehammer for this small tweak that hopefully requires just a mallet. Is it the theme that generates the contents of the title tag or is that part of core WordPress? Thanks!

Hi there,

WordPress handles the title tag, but you can filter it quite easily:

add_filter( 'document_title_parts', function( $title ) {
    unset( $title['site'] );

    return $title;
} );

Let me know if that does it or not :)

GP doesn't call the title - WordPress does. That article is how WP used to add the title tag, but now it uses document_title_parts.

Did my code not work?

I didn't test it yet, was trying to decipher to the filter code first to ensure the homepage shows the title but the post pages only display the post title. Wasn't clear if this kills the title across the board (due to my ignorance, not necessarily because it isn't right:). Thanks for chiming in with non-GP help, I appreciate it!

Ah, to do that, try this:

add_filter( 'document_title_parts', function( $title ) {
    if ( is_singular() ) {
        unset( $title['site'] );
    }

    return $title;
} );

Awesome, works perfectly (so far). Thank you!

You're welcome :)

I just migrated managed Wordpress from Media Temple to Dreamhost and Dreamhost includes Jetpack Pro. The Pro SEO tool includes this sort of functionality and granular by page, tag, etc. Just for reference and obviously I'll take advantage of the simple UI once I sort through all the migration nits.

This archived topic is closed to new replies.