Site logo

Archived topic

Primary navigation below featured image only on blog and archive pages

11 replies · Started by Joey on June 26, 2020

Viewing posts 1–12 of 12

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.

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 );
    }
}  

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.

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 );
}  

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?

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

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

Glad we could be of help

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.

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

Glad to hear that!

This archived topic is closed to new replies.