I want to change every ul,li tags into div tags of wordpress header.wp_nav_menu() is always returns ul ,li.This is I want to change.
<ul>
<li>Home</li>
<li>Services</li>
<li>Products</li>
</ul>
This must be change like this.
<div>
<div>Home</div>
<div>Services</div>
<div>Products</div>
</div>
Please help me. Thanks.
To add a custom navigation menu, the first thing you need to do is register your new navigation menu by adding this code to your theme's functions. php file. add_action( 'init' , 'wpb_custom_new_menu' ); You can now go to Appearance » Menus page in your WordPress admin and try to create or edit a new menu.
Head over to Appearance » Menus page in your WordPress admin and click on the Screen Options button. Once you have checked that box, you will see that an additional field is added when you go to edit each individual menu item. Now you can use this CSS class in your stylesheet to add your custom CSS.
To Edit Appearance, Widgets, and Themes: On the dashboard sidebar at the left-hand side of your screen, you will see a section named Personalize. Underneath this, there are two options, Themes, and Menus. These two options are where you can find all of your appearance customization settings.
You need a custom walker to do that, an modified version of this one answered by toscho, just paste this class in your functions.php
class Description_Walker extends Walker_Nav_Menu
{
function start_el(&$output, $item, $depth, $args)
{
$classes = empty($item->classes) ? array () : (array) $item->classes;
$class_names = join(' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
!empty ( $class_names ) and $class_names = ' class="'. esc_attr( $class_names ) . '"';
$output .= "<div id='menu-item-$item->ID' $class_names>";
$attributes = '';
!empty( $item->attr_title ) and $attributes .= ' title="' . esc_attr( $item->attr_title ) .'"';
!empty( $item->target ) and $attributes .= ' target="' . esc_attr( $item->target ) .'"';
!empty( $item->xfn ) and $attributes .= ' rel="' . esc_attr( $item->xfn ) .'"';
!empty( $item->url ) and $attributes .= ' href="' . esc_attr( $item->url ) .'"';
$title = apply_filters( 'the_title', $item->title, $item->ID );
$item_output = $args->before
. "<a $attributes>"
. $args->link_before
. $title
. '</a></div>'
. $args->link_after
. $args->after;
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
}
}
call wp_nav_menu
in header.php
like following
wp_nav_menu(
array (
'menu' => 'main-menu',
'container' => 'div', // parent container
'container_id' => 'my_nav', //parent container ID
'depth' => 1,
'items_wrap' => '%3$s', // removes ul
'walker' => new Description_Walker // custom walker to replace li with div
)
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With