• Hello,

    can’t find anything on this topic.

    Scenario:
    I am currently developing a website, that has two menus. If a specific menu item is clicked, the menu switches to the other menu and vice-versa. Not only the menu needs to change, but also the header and footer need to change.

    How can this be done?

    The current code is below. The basic functionality is to monitor if the visitor is on the page (the specific menu item). If yes, the menu switches.

    /**
    * Function for changing the menu dynamically depending on if the visitor is on the rental or sales-themed page.
    */
    function myprefix_wp_nav_menu_args( $args = '' ) {
    	global $wp_query; // create global wp_query.
    	$post = $wp_query->get_queried_object(); // get queried object.
    	$post_id = $post->ID; // get current page id.
    
    	if ( $post_id == '247' ) { // show sales menu.
    		$args['menu'] = 48;
    	} 
    	else if ( $post_id == '245') { // show rental menu.
    		$args['menu'] = 6;
    	} 
    	return $args;
    }
    add_filter( 'wp_nav_menu_args', 'myprefix_wp_nav_menu_args' );

    Any help appreciated. Thanks in advance & all the best,
    Mick

    • This topic was modified 2 years, 10 months ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not an Everything else WordPress topic
Viewing 1 replies (of 1 total)
  • Maybe you can create a category for the special items and create a custom template for that category with the header and footer you want. You could then create a menu based on categories.

Viewing 1 replies (of 1 total)
  • The topic ‘Change header and footer based on active menu item’ is closed to new replies.