Site logo

Archived topic

Remove the element from frontpage

7 replies · Started by Carsten on April 4, 2023

Viewing posts 1–8 of 8

Hi there, how do I remove the header from the frontpage only?

I have added this condition to the code from the documentation https://docs.generatepress.com/article/generate_header/
but it has no effect, and displays the header on other pages as well.

add_action( 'after_setup_theme', 'tu_remove_header' );
function tu_remove_header() {
    if ( is_front_page() ) {
        remove_action( 'generate_header', 'generate_construct_header' );
    }
}

Thanks

Hi Ying, I really want to add the function to my functions.php instead, so any idea why the code should not work here?

Thanks

Can you link me to your site?

Sure

Try this code instead:

add_action( 'wp', 'tu_remove_header' );
function tu_remove_header() {
    if ( is_front_page() ) {
        remove_action( 'generate_header', 'generate_construct_header' );
    }
}

Hi Ying

Thank you, it is working perfectly.

Just curius on, why the other code snippet is not working when the if is_front_page statement is added?

When after_setup_theme doesn't work, try wp :)

This archived topic is closed to new replies.