[英]How to add a another li container after ul container wp_nav_menu wordpress and other html tag?
[英]How to add div after parent container for wp_nav_menu?
function add_custom_nav( $items, $args ) {
if( $args->theme_location == 'menu-1' ) {
return "<div>I AM going CraZY</div>" . $items;
}
return $items;
}
add_filter('wp_nav_menu_items','add_custom_nav', 10 , 2);
我查阅了很多示例,但是当我尝试调用它时,没有任何变化。
<?php wp_nav_menu( array( 'theme_location' => 'menu-1' ) ); ?>
您可以使用Walker类在特定类之后添加元素。
在您的function.php
添加类似的内容,
class Walker_Nav_Pointers extends Walker_Nav_Menu
{
function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
$output .= sprintf( "\n<li><a href='%s'%s>%s</a></li>\n",
$item->url,
( $item->object_id === get_the_ID() ) ? ' class="current"' : '',
$item->title
// Add your code to add your elements.
);
}
}
然后,
<?php
wp_nav_menu(array('walker' => new Walker_Nav_Pointers()););
?>
检查一下 。 希望这会帮助你。 谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.