首页 > 解决方案 > How to get specific menu item from a custom Wordpress menu?

问题描述

I want to be able to grab a single item from a custom Wordpress menu.

For example, if my menu displays as "Home About Contact", I want to be able to grab just "Home" to generate it elsewhere in the site.

Here is the code I'm using to get the entire menu in the page.

<?php
  wp_nav_menu( array( 
  'theme_location' => 'left-menu', 
  'container_class' => 'li' ) ); 
?>

And here is the custom menu code in the functions.php (if you need it)

function wpb_custom_new_menu() {
register_nav_menus(
array(
  'left-menu' => __( 'C3 Left Menu' ),
)
);
}
add_action( 'init', 'wpb_custom_new_menu' );

标签: phpwordpress

解决方案


您可以简单地将菜单放在您希望使用的位置wp_nav_menu,然后使用 CSS 隐藏除第一个以外的所有菜单项?


推荐阅读