Snippets: How to Display Custom Menus Based on the Current Page

The Total theme includes a handy filter named "wpex_custom_menu" which will allow you to conditionally alter the ID of the main menu so you can easily display different menus for your main header menu depending on the current page/section of your website. Below is an example snippet you can use as an example and modify accordingly.

// Use menu with ID 60 for blog all blog posts and archives
add_filter( 'wpex_custom_menu', function( $menu_id ) {

	// Display different menu for blog
	if ( wpex_is_blog_query() ) {
		$menu_id = '60';
	}

	// Return menu
	return $menu_id;

} );

Snippet Type: PHP

Posted Under: Menu

All PHP snippets should be added via a child theme's functions.php file.