Site logo

Archived topic

Disable Elements: Featured Image / Page Header

5 replies · Started by Dean on April 8, 2018

Viewing posts 1–6 of 6

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 :-)

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 :)

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 :-)

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 :)

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! :-)

Awesome - thanks for sharing the solution! :)

This archived topic is closed to new replies.