How to reposition Primary Navigation conditionally in Genesis

Posted on

In Genesis Facebook group, a user asks:

HELP > I need to reposition the Primary navigation ONLY in the blog pages.
Currently, the primary nav is after the header, and I need to put it before the header in the blog page (also in single post page, category page, archive page and search results page). I tried a function but I have the white screen, so it’s clearly poorly formed.
I’m using Genesis Sample.
I appreciate any suggestion.

We can place the reposition code inside a function hooked at a location that is immediately above the top most hook (contained inside the function) so an if conditional can be set.

While the tutorial has been written for Genesis Sample child theme it should work with minor adjustments in any Genesis child theme.

Adding the following in child theme’s functions.php will place the Primary Navigation above the header on single Posts, archives (incl. category pages) and search pages:

// Reposition the primary navigation menu conditionally
add_action( 'genesis_before', 'sk_resposition_primary_nav' );
function sk_resposition_primary_nav() {

	// if we are not on a single Post page or archive page or search results page, abort.
	if ( ! ( is_singular( 'post' ) || is_archive() || is_search() ) ) {
		return;
	}

	remove_action( 'genesis_after_header', 'genesis_do_nav' );
	add_action( 'genesis_before_header', 'genesis_do_nav' );

}