简体   繁体   中英

add custom attribute to wordpress navigation

in wordpress admin panel when i create a nav menu , i can set title and class for each <a> in html structure . in wordpress codex we can add setting for <ul> like below :

<?php

$defaults = array(
    'theme_location'  => '',
    'menu'            => '',
    '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 );

?>

the problem is how i can add some attribute like data-hover in my nav generator of wordpress ? any body can help how can add custom attribute to each <a> of nav menu .

You could create a custom walker for the menu. Please see here for an example: http://codex.wordpress.org/Function_Reference/wp_nav_menu#Using_a_Custom_Walker_Function

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM