我安装了带有子主题的Genesis框架。我的客户希望他们的主题“购物车”短代码是他们主导航中的最后一个菜单项,无论有多少个菜单项。
短代码:
echo do_shortcode(\'[shopping_cart]\');
当前代码:
$nav_output = sprintf
( \'<div id="nav">%2$s%1$s%3$s</div>\', $nav, genesis_structural_wrap( \'nav\', \'<div class="wrap">\', 0 ), genesis_structural_wrap( \'nav\', \'</div><!-- end .wrap -->\', 0 ) );
echo apply_filters( \'genesis_do_nav\', $nav_output, $nav, $args );
}
}
电流输出:
<div id="nav">
<div class="wrap">
<ul id="menu-main-navigation-menu" class="nav">
<li id="menu-item-91" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-91">
<li id="menu-item-29" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-29">
<!-- this is where the shortcode should be placed, just before closing the list -->
</ul>
</div>
</div>
SO网友:xyz
试试这个,带下拉菜单
function my_contact_item($items, $args) {
if( $args->theme_location == \'primary\' )
return $items . \'<li class="myclass"><a href="http://example.com">My link title</a><ul class="sub-menu"><li><div style="width:350px;">\' . do_shortcode(\'[My_Shortcode]\') . \'</div></li></ul></li>\';
}
add_filter(\'wp_nav_menu_items\',\'my_contact_item\', 10, 4);
无下拉列表
function my_contact_item($items, $args) {
if( $args->theme_location == \'primary\' )
return $items . \'<li class="myclass"><a href="http://example.com">My link title</a>\' . do_shortcode(\'[My_Shortcode]\') . \'</li>\';
}
add_filter(\'wp_nav_menu_items\',\'my_contact_item\', 10, 4);