Wordpress使用编辑器将菜单添加到页面内容

时间:2014-12-29 07:07:04

标签: php wordpress-plugin wordpress-theming wordpress

我可以在外观中管理自定义菜单 - >菜单

然后,我可以通过在编辑器中插入这样的短代码,将任何这些自定义菜单添加到页面内容中:

[menu name="Menu1"]

问题:

如何向编辑器添加下拉列表(如格式,甚至在格式中),这将列出所有可用的自定义菜单。单击自定义菜单时,应将其短代码插入页面内容。

1 个答案:

答案 0 :(得分:0)

<?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' );
?>

然后使用这样的短代码 [菜单名称=&#34; menu_name&#34;]

相关问题