Hi Felice,
The first code seems about right.
One reason I can think of why it isn’t working is likely because the condition isn’t correct.
Perhaps, the ID indicated in the is_page() isn’t correct.
If you can point me to the page you’re trying to remove the header on, I can help out in pointing you to the correct ID.
Hi @ejcabquina thanks for your time.
The page I’m working is this, and the ID is 6.
// remove header
add_action( 'after_setup_theme','tu_remove_header' );
function tu_remove_header() {
if ( is_page( 6 ) ) {
remove_action( 'generate_header','generate_construct_header' );
}}
-
This reply was modified 5 years ago by
FeliceAntonio. Reason: added code
Well, I found in this website (Step 3: Insert the Code into functions.php) a good solution, so I can work just on functions.php file of child theme, without touching custom CSS.
Practically, I add <style>.site-header, .site-footer{display:none;}</style> in page where remove header and footer.
Always Thanks for your time, and GP Team too.
See you soon!
Have you fully sorted it out? Thanks for sharing that with us.
Reminder: Removing the header through PHP will always be better than CSS because there are potential site performance improvements.
I agree. I always try, when possible, to solve with PHP, but in this case I did not understand why the code I used did not work.
I think it’s because you’re using the wrong hook.
I don’t think the is_page() functions can be used on after_theme_setup.
What happens if you use this?
add_action( 'wp','tu_remove_header' );
function tu_remove_header() {
if( is_page(819) ){
remove_action( 'generate_header', 'generate_construct_header');
}
}
Thanks a lot, it works like a charm!!!
I didn’t think, and I didn’t know, about is_page () could not work well with after_theme_setup.
Always thanks for your time and the great support -:)
I wasn’t sure at first as well. I had to check back if the query is run before or after the after_theme_setup.
is_page() wasn’t working because after_theme_setup is run before the query so the is_page() was always returning FALSE.