[Resolved] Disable Elements: Featured Image / Page Header

Home Forums Support [Resolved] Disable Elements: Featured Image / Page Header

Home Forums Support Disable Elements: Featured Image / Page Header

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #544274
    Dean

    Hi Tom.

    I have a global page header set up for pages. In this page header, I am displaying a H1 tag using “{{post_title}}”. However, the only page I do not wish this to be added to is the homepage. So, on the homepage under disable elements I have disabled “Featured Image / Page Header”.

    When I check the page source however, I see the page header with H1 tag is still there, and has just been hidden with display none in css:

    .generate-page-header, .page-header-image, .page-header-image-single {
        display: none;
    }

    This therefore leads to having two H1 tags in the source code which is not good for search engines who may see this as keyword stuffing etc.

    I can see GP is usually super clever about this and automatically disables the content title H1 when a page header is set for a page.

    But how about in the case I described above? Is there something that can be done? I can only think of two ways to solve this:

    1) Create another empty page header (no H1 tag in there) and manually set it at the bottom of the edit page scree for the homepage.

    2) Manually set each pages page header and then simply not set one for the homepage.

    However, both of these methods seem like a bodge and that the disable elements option on the homepage, should stop the page header from being in the source code altogether.

    Am I missing anything here?

    Thank you πŸ™‚

    GeneratePress 2.0.2
    GP Premium 1.6.2
    #544595
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Disable Elements is being rebuilt, and will include some more logic for things like this.

    For now, we can use PHP:

    add_action( 'after_setup_theme', 'tu_remove_page_header' );
    function tu_remove_page_header() {
        if ( is_front_page() && get_post_meta( get_the_ID(), '_generate-disable-post-image', true ) ) {
            remove_action( 'generate_after_header', 'generate_page_header' );
        }
    }

    Let me know if this helps or not πŸ™‚

    #544883
    Dean

    Hi Tom.

    Unfortunately that won’t work in my case. The user may wish to add a page header to the homepage after I have set it up :-/.

    Based on your response though I am thinking to go with my suggested option 1 above as a temporary fix knowing the new Disable Elements is on its way. Do you have a rough ETA of when it may be released? I assume this is related to Gutenberg and so will be released after Gutenberg’s release?

    Thank you Tom πŸ™‚

    #545501
    Tom
    Lead Developer
    Lead Developer

    I just adjusted the code above so it will only apply if the disable elements option is checked. So if the user decides they want the page header on that page, they just need to uncheck the disable elements option πŸ™‚

    #545914
    Dean

    Hi Tom.

    Spot on! I just needed to change the hook as ‘after_setup_theme’ is a bit too early so wouldn’t work with “is_front_page()”. So for anyone else reading the final solution looks like this:

    add_action( 'get_header', 'tu_remove_page_header' );
    function tu_remove_page_header() {
        if ( is_front_page() && get_post_meta( get_the_ID(), '_generate-disable-post-image', true ) ) {
            remove_action( 'generate_after_header', 'generate_page_header' );
        }
    }

    Thank you Tom! πŸ™‚

    #545926
    Tom
    Lead Developer
    Lead Developer

    Awesome – thanks for sharing the solution! πŸ™‚

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