Site logo

[Resolved] Remove the element from frontpage

Home Forums Support [Resolved] Remove the element from frontpage

Home Forums Support Remove the element from frontpage

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #2596761
    Carsten

    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

    #2596787
    Ying
    Staff
    Customer Support

    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.

    #2596813
    Carsten

    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

    #2596919
    Ying
    Staff
    Customer Support

    Can you link me to your site?

    #2596957
    Carsten

    Sure

    #2596978
    Ying
    Staff
    Customer Support

    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' );
        }
    }
    #2597014
    Carsten

    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?

    #2597113
    Ying
    Staff
    Customer Support

    When after_setup_theme doesn’t work, try wp 🙂

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.