Archived topic
Remove the element from frontpage
7 replies · Started by Carsten on April 4, 2023
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 Carsten,
You can use a layout element to remove the header without using code.
https://docs.generatepress.com/article/layout-element-overview/
Please be noted, if the navigation as header option is enabled, then the code will not work, as there's no header but only navigation on your site.
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 :)