- This topic has 13 replies, 2 voices, and was last updated 6 years, 10 months ago by Tom.
-
AuthorPosts
-
May 6, 2017 at 12:38 am #314658Minh
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 #314659TomLead 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 #314665MinhHi 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 #314744TomLead 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 #316260MinhHi 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 #316342TomLead DeveloperLead DeveloperCan you try changing your navigation location to after the header in Customize > Layout > Primary Navigation?
May 10, 2017 at 9:45 pm #316575MinhHi 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 #316605TomLead 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 #316612MinhNot working, Tom. ๐
May 11, 2017 at 12:31 am #316613TomLead DeveloperLead DeveloperJust made another adjustment, try the new code.
May 11, 2017 at 12:36 am #316616MinhStill floating right, Tom.
May 11, 2017 at 12:41 am #316618TomLead 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 #316698MinhThat works! Thank you very much Tom.
May 11, 2017 at 9:23 am #316779TomLead DeveloperLead DeveloperYou’re welcome ๐
-
AuthorPosts
- You must be logged in to reply to this topic.