• When I hover my mouse over the browser tab on the homepage only the global site title is displayed (no page title prefixed). Same situation when I view source.

    All other pages behave normally.

    How do I get the page title followed by site title into the homepage source view?

    I am using Generatepress free with a child theme.

    • This topic was modified 2 years, 9 months ago by grey4radar.

    The page I need help with: [log in to see the link]

Viewing 15 replies - 1 through 15 (of 16 total)
  • ying

    (@yingscarlett)

    Hi there,

    That’s the normal behavior, if you switch to twenty twenty series theme, it should be the same case.

    I think a SEO plugin is what you are looking for ??

    Thread Starter grey4radar

    (@grey4radar)

    @ying – Thanks for your reply.

    Does anybody know of a way around this without a plugin?

    Hi there,

    its a WP function that has its own wp_title filter:

    https://developer.www.ads-software.com/reference/functions/wp_title/

    So you can use a PHP Snippet to change it. For example:

    function db_custom_page_title( $title , $separator) {
        // if front page
        if( is_front_page() ){ 
            // set custom title 
            $title = 'your custom title goes here';
    
        }
        return $title;  
    }
    
    add_filter( 'wp_title', 'db_custom_page_title', 10 , 2 );

    This checks for a static home page and returns whatever you add to the $title variable.

    Thread Starter grey4radar

    (@grey4radar)

    Should I place that code in the functions.php of the child theme?

    Yes – sorry i should have said.
    For more info on Adding PHP see here:

    https://docs.generatepress.com/article/adding-php/

    Thread Starter grey4radar

    (@grey4radar)

    I have added the snippet to the functions.php of the child theme.
    Checked in multiple browsers (also private windows), cleared caches.
    Does not work.

    Ok – try this snippet instead:

    add_filter( 'document_title_parts', 'db_change_doc_title', 15,1 );
    
    function db_change_doc_title( $title ){
        if( is_front_page() ) { 
            $title_parts_array['title'] = 'your custom title goes here';
        }
        return $title_parts_array;
    }

    Note: this assumes you have a static page set for your home page.

    Thread Starter grey4radar

    (@grey4radar)

    That ony works if I’m logged into WordPress admin in another tab.
    When I log out and refresh, it reverts to Site Title only.

    Do you have any plugin/server page caching enabled ?

    Thread Starter grey4radar

    (@grey4radar)

    I have literally just turned off caching on the server as you were replying.
    Bingo – it works.
    Thank you very much for your help David.

    Glad to be of help!

    Thread Starter grey4radar

    (@grey4radar)

    Sorry, back again.

    Server side caching is still off and browswer caches cleared.

    When using this.

    add_filter( 'document_title_parts', 'db_change_doc_title', 15,1 );
    
    function db_change_doc_title( $title ){
        if( is_front_page() ) { 
            $title_parts_array['title'] = 'Daves code works';
        }
        return $title_parts_array;
    }

    The homepage is fine but all other pages in various browsers (logged in or not) show the following error at the top of the page.

    Warning: array_filter() expects parameter 1 to be array, null given in /public_html/site/wp-includes/general-template.php on line 1265
    Warning: implode(): Invalid arguments passed in /public_html/site/wp-includes/general-template.php on line 1265

    Line 1265 has the following.
    $title = implode( " $sep ", array_filter( $title ) );

    Thread Starter grey4radar

    (@grey4radar)

    Just an FYI.
    PHP version is 7.4.28

    Hi @grey4radar

    On this line – function db_change_doc_title( $title ){

    Can you change $title to $title_parts_array?

    So the code is actually pointing to the correct array.

    Thread Starter grey4radar

    (@grey4radar)

    Hi Elvin

    That seems to have fixed it.
    Thanks for your help.

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘Page title is missing from title tag on homepage only.’ is closed to new replies.