- This topic has 11 replies, 3 voices, and was last updated 1 year, 9 months ago by David.
-
AuthorPosts
-
June 26, 2020 at 7:04 pm #1343221Joey
My blog page has a full page image added to it via elements page hero (https://simipress.com/home/). I used the following code to move the primary navigation below the image. It has the same effect on featured images of the blog, which are also full page photos via elements.
add_action( 'after_setup_theme','craig_move_navigation' ); function craig_move_navigation() { remove_action( 'generate_after_header', 'generate_add_navigation_after_header', 5 ); add_action( 'generate_after_header', 'generate_add_navigation_after_header', 15 ); }
The trouble is, the above code also moves the primary navigation below images in regular pages where there is a featured image, full page or not. How can I adjust the above code so that the navigation is only changed on the pages associated with blog posts? (Main blog page hero and all individual blog posts featured images) I’ve scourged the forums but can’t find this exact change. Thanks in advance.
June 27, 2020 at 1:52 am #1343371DavidStaffCustomer SupportHi there,
try this:
add_action( 'wp','db_single_post_move_navigation' ); function db_single_post_move_navigation() { if ( is_single() || is_home() ) { remove_action( 'generate_after_header', 'generate_add_navigation_after_header', 5 ); add_action( 'generate_after_header', 'generate_add_navigation_after_header', 15 ); } }
June 27, 2020 at 2:42 pm #1343992JoeyHi David,
Your code works for single posts, which I need, but I need it to work as well for the main blog page.(https://simipress.com/home/)
It is an issue because some of my pages don´t have full screen images (as in this page https://simipress.com/submissions/) and it makes the heading look weird. Another way to handle it would be to lower the header on all full page images, whichever is easier. Thanks for responding so soon.
June 27, 2020 at 5:10 pm #1344066LeoStaffCustomer SupportTry removing the conditional tag instead:
add_action( 'wp','db_single_post_move_navigation' ); function db_single_post_move_navigation() { remove_action( 'generate_after_header', 'generate_add_navigation_after_header', 5 ); add_action( 'generate_after_header', 'generate_add_navigation_after_header', 15 ); }
June 27, 2020 at 7:26 pm #1344104JoeyLeo, it didn’t work. It has the same effect as my original code.
Worse comes to worst I can not do featured images on pages, and figure out a way to put the first post image above the title. Other ideas?
June 28, 2020 at 5:56 am #1344349DavidStaffCustomer SupportI edited the code here – it now checks if it is a single post or the blog page.
June 28, 2020 at 3:39 pm #1344878JoeyThat worked David, thank you both. I need to learn PHP so I can do this myself.
June 29, 2020 at 1:06 am #1345140DavidStaffCustomer SupportGlad we could be of help
July 19, 2022 at 2:51 am #2287096JoeyThis is an old post, but the code is broken on my front page (it still works fine for posts). It isn’t putting the primary menu below the top image anymore.
I changed my Front Page from the blog to a static page (link is below). I don’t know if that is why. In other words,
is_single()
is working correctly on blog posts, butis_home()
isn’t working on the menu of my landing page any more.I can open a new topic if that would be better. Thank you.
July 19, 2022 at 5:43 am #2287215DavidStaffCustomer SupportHi there,
did you fix this ?
is_home()
is for the Blog page
is_front_page()
is for a static home page.More on that here:
https://docs.generatepress.com/article/using-hooks-conditional-tags/
July 19, 2022 at 2:39 pm #2287874JoeyThank you for that link, that’s what I was looking for. It’s working as it should now.
July 20, 2022 at 1:56 am #2288176DavidStaffCustomer SupportGlad to hear that!
-
AuthorPosts
- You must be logged in to reply to this topic.