Skip to content

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

The Total theme includes a handy filter named "totaltheme/header/menu/wp_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( 'totaltheme/header/menu/wp_menu', function( $menu_id ) {

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

	// Return menu
	return $menu_id;

} );
All PHP snippets should be added via child theme's functions.php file or via a plugin. We recommend Code Snippets (100% Free) or WPCode (sponsored)
Back To Top