[Resolved] Posts Page (the default 'blog') Title Won't Change When Page Is Changed

Home Forums Support [Resolved] Posts Page (the default 'blog') Title Won't Change When Page Is Changed

Home Forums Support Posts Page (the default 'blog') Title Won't Change When Page Is Changed

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #917147
    Riley

    We are using both GP and the GP Premium Plugin on a brand new site we are building. When we try to change the Posts Page to a new page (or even rename the default blog page) the slug in the URL can change, but the title itself which appears in the header on the page does not change. It remains ‘blog’. (Except in one situation where: we renamed the blog page to lessons, the title remained ‘blog’, then we renamed it to Lessons1, still ‘blog’, created another page called ‘lessons’, pointed the Posts Page to ‘lessons’, then the title said ‘lessons1’, when it should have said ‘lessons’.)

    #917149
    Riley

    Also (I can create another ticket for this, but it seems related), we disabled the footer on this page, but the footer still appears.

    #917186
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Are you using a Header Element? If so, try this PHP:

    add_filter( 'generate_page_hero_post_title', function( $title ) {
        if ( is_home() ) {
            $title = 'Your new title';
        }
    
        return $title;
    } );

    How did you disable the footer? I’m not able to see your site (it’s coming soon).

    #917248
    Riley

    I believe we are using the default Global Header. But we shouldn’t have to use PHP code, the default ‘blog’ page should automatically show the same title as the title of the page, correct? I mean, this is the case for every other single page. (The difference between all other pages and the one we are having issues with is that we are assigning this page as the ‘Posts Page’ in the Customizer.)

    And for the footer, I need to make a correction. In the page editor, in the Layout section, we are settings widgets to 0, yet the three default widgets still appear.

    We are using the ‘Catalyst’ site layout from your Site Library.

    I’ll disable the cover for now, but will throw it back up in a couple hours. (The page which we are having issues on is the Videos page.)

    #917345
    Tom
    Lead Developer
    Lead Developer

    If the page is the posts page, it will default to “Blog”. This is because WordPress disconnects itself from the actual page if it’s set as the posts page. The function I shared should work.

    So while editing the page content, you’ve used the “Layout” metabox to set the widgets to 0? This is the same issue as above, WordPress doesn’t listen to the page settings when it’s set as the posts page. You’ll need to set the widgets to 0 in the Customizer (Customize > Layout > Footer).

    #917362
    Riley

    Those work, thank you!

    #917773
    Tom
    Lead Developer
    Lead Developer

    You’re welcome ๐Ÿ™‚

    #986762
    William

    Sorry, I have encountered the same problem. Exactly where should this php be inserted?

    Thanks

    #986782
    Leo
    Staff
    Customer Support

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

    Code Snippets is the easiest method if you aren’t using a child theme already.

    #986868
    William

    Thanks, worked! Sorry again for the basic question, I’m new to using the child themes.

    #986916
    Leo
    Staff
    Customer Support

    No problem ๐Ÿ™‚

    #1631944
    Angelo

    Tom, hardcoding the word “Blog” into GP Premium is very unintuitive. It took me 30+ mins of Googling and searching the source code to find your solution.

    You should to add your snippet to these doc pages:

    https://docs.generatepress.com/article/header-element-overview/
    https://docs.generatepress.com/article/header-element-template-tags/

    I think it makes more sense to use the name of the static page as a fallback instead of the word “Blog”. I modified your function to grab the static page name:

    
    add_filter( 'generate_page_hero_post_title', 'cc_page_hero_title' );
    function cc_page_hero_title($original_title)
    {
    	if(is_home()){
    		$static_page_id = get_option('page_for_posts', true);
    		if($static_page_id){
    			return get_the_title($static_page_id);
    		}
    	} else {
    		return $original_title;
    	}
    
    }
    
Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.