admin管理员组

文章数量:1414621

I am searching for a way to display a different menu according to postID:

ex:

if ($post->ID == 2309) {
   displayMenu("menu2");
}

I am using Avada and looked into header.php with no success.

I am searching for a way to display a different menu according to postID:

ex:

if ($post->ID == 2309) {
   displayMenu("menu2");
}

I am using Avada and looked into header.php with no success.

Share Improve this question asked Sep 9, 2019 at 10:57 yarekyarek 1274 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

You can use wp_nav_menu($args) to display different menus. Just pass menu ID, slug, name or object as $args['menu'] parameter.

if ( $post->ID == 2309 ) {
  $args = array(
    'menu' => 'some-menu'
  );
  wp_nav_menu($args);
}

There are also other available parameters that you can pass to the function, https://developer.wordpress/reference/functions/wp_nav_menu/

本文标签: how to display different menu according to postid