【问题标题】:Wordpress add menu to page content using editorWordpress 使用编辑器将菜单添加到页面内容
【发布时间】:2014-12-29 07:07:03
【问题描述】:

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

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

[menu name="Menu1"]

问题:

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

【问题讨论】:

标签: php wordpress wordpress-theming


【解决方案1】:
<?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' );
?>

然后使用这样的简码 [菜单名称=“菜单名称”]

【讨论】:

  • 我可以手动添加简码,知道菜单名称。问题是我是否可以向可视化编辑器添加一个选项,以便我可以从列表中选择菜单。单击所选菜单应自动插入相应的短代码。
  • 为此您必须创建简码 TinyMCE 编辑器按钮
猜你喜欢
  • 2014-12-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-12
  • 2023-03-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多