[Resolved] Hook after header a menu item

Home Forums Support Hook after header a menu item

Viewing 15 posts - 1 through 15 (of 24 total)
  • Author
    Posts
  • #906387
    Sebastien

    Hi,

    I would like to implement a Menu item called “NavServiceBar” into a GP Element > Hook > after header.
    Also, I would like to display this menu item ‘inline’ instead of verticaly.
    How can I do please?

    Thanks

    #906800
    David
    Staff
    Customer Support

    Hi there,

    why not use the Secondary Navigation?

    #906806
    Sebastien

    Can I ?
    I’ve linked to my initial post, a link to the page.

    The position where I want to display this Menu item, is between the header and the breadcrump (where it is written: nav)
    note: the header is generated by a GP element Header.

    #906808
    David
    Staff
    Customer Support

    Yes, so follow these steps:

    1. Create New Hook give it a title.
    2. Add this as the content:

    <div class="second-nav grid-container">
    	<?php generate_secondary_navigation_position(); ?>	
    </div>

    3. Select the after_header hook
    4. Check Execute PHP
    5. Set the Priorty: 15
    6. Set your display rules for the entire site ( or wherever )

    Then in Customizer > Layout > Secondary Navigation set Location: No Navigation.

    Just make sure you have a menu assigned to the Secondary Nav.

    #906830
    Sebastien

    I guess this line in wp-config define('DISALLOW_FILE_EDIT',1); unables me to add PHP in GP Hook.
    Is there something I can do to allow php only into GP Hook ?
    Maybe I don’t understand, but I didn’t find the solution there https://docs.generatepress.com/article/disallow-php-execution/

    I’ve tried to add into function.php childthem:

    add_action( 'after_setup_theme', 'tu_remove_hooks_php_check' );
    function tu_remove_hooks_php_check() {
        remove_action( 'admin_notices','generate_hooks_php_check' );
    }

    but the warning msg remains: Unable to execute PHP as DISALLOW_FILE_EDIT is defined.

    #906899
    David
    Staff
    Customer Support

    Leo provides a function for hooking in the secondary nav here on point 4:

    https://generatepress.com/forums/topic/creating-specific-header/#post-684673

    #906921
    Sebastien

    Thanks,

    add_action( 'after_setup_theme','lh_move_secondary_navigation' );
    function lh_move_secondary_navigation() {
        remove_action( 'generate_after_header', 'generate_add_secondary_navigation_after_header', 7 );
        add_action( 'generate_after_header', 'generate_add_secondary_navigation_after_header', 15 );
    }

    This function hook a second nav under page hero in entire website.

    Can I match this function with rules of a GP Element to display this function into specific pages only?

    #906966
    Leo
    Staff
    Customer Support

    You’d have to use conditional tags similar to this example here:
    https://generatepress.com/forums/topic/different-logos-on-different-with-sticky/#post-875076

    Let me know 🙂

    #906994
    Sebastien

    Hi Leo,
    I’m not familiar with functions.

    1) Firstly I’ve tried this code to add the secondary navigation item under my header:

    add_action( 'after_setup_theme','lh_move_secondary_navigation' );
    function lh_move_secondary_navigation() {
        remove_action( 'generate_after_header', 'generate_add_secondary_navigation_after_header', 7 );
        add_action( 'generate_after_header', 'generate_add_secondary_navigation_after_header', 15 );
    }

    I’ve matched a menu to the secondary navigation and param the Navigation Location (into Customizer) : Hide secondary bar.

    But nothing is displayed.

    2) about the conditional tag I guess something like this would work? :

    add_action( 'after_setup_theme','lh_move_secondary_navigation' );
    function lh_move_secondary_navigation() {
    
        // Return our category logo URL
        if ( is_page( array( 1, 2, 3, 4, 5 ) )  ) {
        remove_action( 'generate_after_header', 'generate_add_secondary_navigation_after_header', 7 );
        add_action( 'generate_after_header', 'generate_add_secondary_navigation_after_header', 15 );;
        }
    }
    #906998
    Leo
    Staff
    Customer Support

    1. Try below header in the secondary navigation location

    2. Yup that looks good. Just need to change replace 1, 2, 3, 4, 5 to the actual page id or name:
    https://codex.wordpress.org/Conditional_Tags#A_PAGE_Page

    #907004
    Sebastien

    thanks Leo !!
    It works I’m so happy 😀

    But last thing… This actual solution put the content in a div that is full width.
    What I loved with GP Element Hook after header is that is put the content in a section (same width / margin than the body section)
    Is there any way to do the same thing?

    #907040
    Leo
    Staff
    Customer Support
    #907048
    Sebastien

    Thanks you guys for your support!
    GP is so powerfull everysecond it surprises me 😮

    Edit:
    the conditional function doesn’t work:

    add_action( 'after_setup_theme','lh_move_secondary_navigation' );
    function lh_move_secondary_navigation() {
        if ( is_page( array( 4536, 4537, 36, 4538, 4534, 4535 ) )  ) {
        remove_action( 'generate_after_header', 'generate_add_secondary_navigation_after_header', 7 );
        add_action( 'generate_after_header', 'generate_add_secondary_navigation_after_header', 15 );;
        }
    }

    when I use this code, the secondary navigation is displayed under the top bar instead of after header.

    #907063
    Leo
    Staff
    Customer Support

    Hmm was it working before the conditional tag was added?

    #907064
    Sebastien

    yes

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