我是个新手WordPress core 和development process. 因为我对WordPress functions. But I need the help from you guys.
实际上,我正在开发我的第一个主题,我已经有了CSS for my menu. 菜单已在中注册functions.php.
我用过code posted below 添加我的类"mainnav-section".
<?php
$args = [
\'theme_location\' => \'header-menu\',
\'container\' => \'ul\',
\'container_class\'=> \'\',
\'menu_class\' => \'mainnav-section\'
];
wp_nav_menu($args);
?>
And it executed this.
<ul id="menu-header" class="mainnav-section">
<li id="menu-item-511" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children menu-item-511">
<a href="http://#">Latest</a>
<ul class="sub-menu">
<li id="menu-item-512" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-512">
<a href="http://#">HardFork</a>
</li>
</ul>
</li>
<li id="menu-item-513" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-513">
<a href="http://#">Innovations</a>
</li>
</ul>
我只想添加
CSS class 到
main-menu items,
sub-menu 和
list items. 因为我有
CSS and JS completed 获取
desired menu.
SO网友:Howdy_McGee
下面将添加一个名为class-here
至所有菜单项:
/**
* Filters the CSS class(es) applied to a menu item\'s list item element.
*
* @param array $classes The CSS classes that are applied to the menu item\'s `<li>` element.
* @param WP_Post $item The current menu item.
* @param stdClass $args An object of wp_nav_menu() arguments.
* @param int $depth Depth of menu item. Used for padding.
*
* @return Array $classes
*/
function theme_prefix_nav_menu_css_class( $classes, $item, $args, $dpeth ) {
$classes[] = \'class-here\';
return $classes;
}
add_filter( \'nav_menu_css_class\', \'theme_prefix_nav_menu_css_class\', 10, 4 );
您可以将此添加到主题中
functions.php
文件WordPress WP Nav Walker创建菜单时还有一系列其他挂钩-
Check out The Code Reference