Title: Remove header with PHP function
Last modified: June 3, 2021

---

# Remove header with PHP function

 *  Resolved [FeliceAntonio](https://wordpress.org/support/users/antonio_09/)
 * (@antonio_09)
 * [5 years ago](https://wordpress.org/support/topic/remove-header-with-php-function/)
 * Hi to everyone.
    I’m looking for remove `header` in specific page with PHP. I
   found [this code](https://wordpress.org/support/topic/control-combobox-and-remove-header/)
   and [this too](https://docs.generatepress.com/article/generate_header/) but it
   doesn’t work. In child theme’s `functions.php` file I tried these solutions, 
   without results:
 *     ```
       add_action( 'after_setup_theme','tu_remove_header' );
       function tu_remove_header() {
       if ( is_page( 123 ) ) {
           remove_action( 'generate_header','generate_construct_header' );
       }}
       ```
   
 * and this
 *     ```
       if ( is_page( 123 ) ){
           remove_action( 'generate_header','generate_construct_header' );
       }
       ```
   
 * I can’t understand where I’m wrong.
    For the moment I use [this CSS code](https://wordpress.org/support/topic/disable-footer-and-header-on-a-specific-page/)
   by Leo. Thanks!

Viewing 8 replies - 1 through 8 (of 8 total)

 *  [Elvin](https://wordpress.org/support/users/ejcabquina/)
 * (@ejcabquina)
 * [5 years ago](https://wordpress.org/support/topic/remove-header-with-php-function/#post-14514719)
 * 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.
 *  Thread Starter [FeliceAntonio](https://wordpress.org/support/users/antonio_09/)
 * (@antonio_09)
 * [5 years ago](https://wordpress.org/support/topic/remove-header-with-php-function/#post-14514841)
 * Hi [@ejcabquina](https://wordpress.org/support/users/ejcabquina/) thanks for 
   your time.
    The page I’m working [is this](https://www.af1.it/policy/), 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](https://wordpress.org/support/users/antonio_09/).
      Reason: added code
 *  Thread Starter [FeliceAntonio](https://wordpress.org/support/users/antonio_09/)
 * (@antonio_09)
 * [5 years ago](https://wordpress.org/support/topic/remove-header-with-php-function/#post-14515466)
 * Well, I found in [this website](https://webhostinghero.org/how-to-hide-the-header-on-specific-pages-in-wordpress/)(
   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!
    -  This reply was modified 5 years ago by [FeliceAntonio](https://wordpress.org/support/users/antonio_09/).
 *  [Elvin](https://wordpress.org/support/users/ejcabquina/)
 * (@ejcabquina)
 * [5 years ago](https://wordpress.org/support/topic/remove-header-with-php-function/#post-14518727)
 * 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.
 *  Thread Starter [FeliceAntonio](https://wordpress.org/support/users/antonio_09/)
 * (@antonio_09)
 * [5 years ago](https://wordpress.org/support/topic/remove-header-with-php-function/#post-14519887)
 * 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.
 *  [Elvin](https://wordpress.org/support/users/ejcabquina/)
 * (@ejcabquina)
 * [5 years ago](https://wordpress.org/support/topic/remove-header-with-php-function/#post-14526110)
 * 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');
       	}
       }
       ```
   
 *  Thread Starter [FeliceAntonio](https://wordpress.org/support/users/antonio_09/)
 * (@antonio_09)
 * [5 years ago](https://wordpress.org/support/topic/remove-header-with-php-function/#post-14526167)
 * 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 -:)
 *  [Elvin](https://wordpress.org/support/users/ejcabquina/)
 * (@ejcabquina)
 * [5 years ago](https://wordpress.org/support/topic/remove-header-with-php-function/#post-14526252)
 * 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.

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Remove header with PHP function’ is closed to new replies.

 * ![](https://i0.wp.com/themes.svn.wordpress.org/generatepress/3.6.1/screenshot.
   png)
 * GeneratePress
 * [Support Threads](https://wordpress.org/support/theme/generatepress/)
 * [Active Topics](https://wordpress.org/support/theme/generatepress/active/)
 * [Unresolved Topics](https://wordpress.org/support/theme/generatepress/unresolved/)
 * [Reviews](https://wordpress.org/support/theme/generatepress/reviews/)

 * 8 replies
 * 2 participants
 * Last reply from: [Elvin](https://wordpress.org/support/users/ejcabquina/)
 * Last activity: [5 years ago](https://wordpress.org/support/topic/remove-header-with-php-function/#post-14526252)
 * Status: resolved