我可以在外观中管理自定义菜单 -> 菜单
然后,我可以通过在编辑器中插入如下简码来将这些自定义菜单中的任何一个添加到页面内容中:
[menu name="Menu1"]
问题:
如何将下拉列表添加到编辑器(如格式甚至格式内部),该列表将列出所有可用的自定义菜单。单击自定义菜单应将其短代码插入页面内容。
<?php
//add this in your functions.php
function custom_menu( $atts ){
$defaults = array(
'theme_location' => '',
'menu' => $atts['name'],
'container' => 'div',
'container_class' => '',
'container_id' => '',
'menu_class' => 'menu',
'menu_id' => '',
'echo' => true,
'fallback_cb' => 'wp_page_menu',
'before' => '',
'after' => '',
'link_before' => '',
'link_after' => '',
'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',
'depth' => 0,
'walker' => ''
);
wp_nav_menu( $defaults );
}
add_shortcode( 'menu', 'custom_menu' );
?>
然后像这样使用简码[菜单名称="menu_name"]