Archived topic
Hook after header a menu item
23 replies · Started by Sebastien on May 21, 2019
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
Hi there,
why not use the Secondary Navigation?
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.
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.
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.
Leo provides a function for hooking in the secondary nav here on point 4:
https://generatepress.com/forums/topic/creating-specific-header/#post-684673
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?
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 :)
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 );;
}
}
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
thanks Leo !!
It works I'm so happy :D
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?
What if change the widths to contained?
https://docs.generatepress.com/article/secondary-navigation-layout/
Thanks you guys for your support!
GP is so powerfull everysecond it surprises me :o
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.
Hmm was it working before the conditional tag was added?
yes