[Resolved] Editing title tag for Google indexing

Home Forums Support [Resolved] Editing title tag for Google indexing

Home Forums Support Editing title tag for Google indexing

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #753082
    Dave

    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!

    #753272
    Leo
    Staff
    Customer Support

    Hi there,

    I believe YoastSEO is something you are looking for.

    https://generatepress.com/forums/topic/empty-on-index/#post-656250

    Let me know if this helps 🙂

    #753277
    Dave

    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!

    #753331
    Tom
    Lead Developer
    Lead Developer

    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 🙂

    #753801
    Dave

    Thanks for the lead – I’m reviewing this page to filter. Hopefully it’s not too outdated. Not seeing where GP calls the title in the code tho, hm.

    https://wordpress.stackexchange.com/questions/95147/remove-site-name-from-title-tag

    #754029
    Tom
    Lead Developer
    Lead Developer

    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?

    #754044
    Dave

    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!

    #754253
    Tom
    Lead Developer
    Lead Developer

    Ah, to do that, try this:

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

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

    #765975
    Tom
    Lead Developer
    Lead Developer

    You’re welcome 🙂

    #807251
    Dave

    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.

Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.