[Resolved] Primary navigation below featured image only on blog and archive pages

Home Forums Support [Resolved] Primary navigation below featured image only on blog and archive pages

Home Forums Support Primary navigation below featured image only on blog and archive pages

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #1343221
    Joey

    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.

    #1343371
    David
    Staff
    Customer Support

    Hi 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 );
        }
    }  
    #1343992
    Joey

    Hi 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.

    #1344066
    Leo
    Staff
    Customer Support

    Try 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 );
    }  
    #1344104
    Joey

    Leo, 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?

    #1344349
    David
    Staff
    Customer Support

    I edited the code here – it now checks if it is a single post or the blog page.

    #1344878
    Joey

    That worked David, thank you both. I need to learn PHP so I can do this myself.

    #1345140
    David
    Staff
    Customer Support

    Glad we could be of help

    #2287096
    Joey

    This 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, but is_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.

    #2287215
    David
    Staff
    Customer Support

    Hi 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/

    #2287874
    Joey

    Thank you for that link, that’s what I was looking for. It’s working as it should now.

    #2288176
    David
    Staff
    Customer Support

    Glad to hear that!

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