- This topic has 13 replies, 2 voices, and was last updated 6 years, 6 months ago by
Tom.
-
AuthorPosts
-
May 6, 2017 at 12:38 am #314658
Minh
Hi GP team,
I was trying to add conditional tags in code snippets but it fails. Like below code: (I wanted the primary navigation appears below the page header ONLY in home page (which is a static page) ):
if ( is_front_page() ) : add_action('after_setup_theme','generate_change_nav_position'); function generate_change_nav_position() { remove_action( 'generate_after_header', 'generate_add_navigation_after_header', 5 ); add_action( 'generate_after_header', 'generate_add_navigation_after_header', 29 ); } endif;
Am I doing wrong?
Thanks.
May 6, 2017 at 12:40 am #314659Tom
Lead DeveloperLead DeveloperAlmost!
Try this:
add_action('after_setup_theme','generate_change_nav_position'); function generate_change_nav_position() { if ( is_front_page() ) : remove_action( 'generate_after_header', 'generate_add_navigation_after_header', 5 ); add_action( 'generate_after_header', 'generate_add_navigation_after_header', 29 ); endif; }
May 6, 2017 at 1:25 am #314665Minh
Hi Tom,
Thank you. Unfortunately it is not how I want. The navigation now is below the logo but not below the entire page header (My home page has an big image in page header).
Fyi: Other than the home page, I want the main navigation to FLOAT right in the rest of the website (with the logo is in the left).
How can I do that?
Sorry for my lack of coding knowledge. Thank you very much Tom!
May 6, 2017 at 9:40 am #314744Tom
Lead DeveloperLead DeveloperCan you link me to your site?
To adjust the navigation location per page you would use this filter: https://docs.generatepress.com/article/navigation-location/#generate_navigation_location
May 10, 2017 at 4:47 am #316260Minh
Hi Tom,
Sorry for the late reply as I was uploading it to a live host. Have a look at this: http://dacsancamau.vn/
Best,
Minh.May 10, 2017 at 7:50 am #316342Tom
Lead DeveloperLead DeveloperCan you try changing your navigation location to after the header in Customize > Layout > Primary Navigation?
May 10, 2017 at 9:45 pm #316575Minh
Hi Tom,
It’s not working. It’s still inside the page header.
The point is: I want the main navigation to sit below the page header (only in the home page), and float right in the rest of the website. So I have to make the main navigation float right by default, and then insert your code with WP conditional tag so that the navigation can sit below the page header in the home page (and the site logo then floats in the center of the header, which I can manage to do).
Thank you Tom.
May 11, 2017 at 12:22 am #316605Tom
Lead DeveloperLead DeveloperThis would be your code then:
add_action('wp','generate_change_nav_position'); function generate_change_nav_position() { if ( is_front_page() ) : remove_action( 'generate_after_header_content', 'generate_add_navigation_float_right', 5 ); add_action( 'generate_after_header', 'generate_add_navigation_float_right', 29 ); endif; }
May 11, 2017 at 12:30 am #316612Minh
Not working, Tom. π
May 11, 2017 at 12:31 am #316613Tom
Lead DeveloperLead DeveloperJust made another adjustment, try the new code.
May 11, 2017 at 12:36 am #316616Minh
Still floating right, Tom.
May 11, 2017 at 12:41 am #316618Tom
Lead DeveloperLead DeveloperHow are you adding the PHP? Technically that shouldn’t be possible.
I just made another tweak, worth a shot.
May 11, 2017 at 5:26 am #316698Minh
That works! Thank you very much Tom.
May 11, 2017 at 9:23 am #316779Tom
Lead DeveloperLead DeveloperYou’re welcome π
-
AuthorPosts
- You must be logged in to reply to this topic.