简体   繁体   English

将自定义属性添加到wordpress导航

[英]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 . 在wordpress管理面板中,当我创建一个导航菜单时,可以为html结构中的每个<a>设置标题和类。 in wordpress codex we can add setting for <ul> like below : 在Wordpress Codex中,我们可以为<ul>添加设置,如下所示:

<?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 ? 问题是如何在wordpress的nav生成器中添加一些属性,例如data-hover any body can help how can add custom attribute to each <a> of nav menu . 任何机构都可以帮助如何向导航菜单的每个<a>添加自定义属性。

You could create a custom walker for the menu. 您可以为菜单创建一个自定义的walker。 Please see here for an example: http://codex.wordpress.org/Function_Reference/wp_nav_menu#Using_a_Custom_Walker_Function 请参见此处的示例: http : //codex.wordpress.org/Function_Reference/wp_nav_menu#Using_a_Custom_Walker_Function

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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