在WordPress主题中我使用bs4navwalker和bootstrap4来显示菜单一切正常但是当悬停在父菜单上时子菜单没有显示
的header.php:
<!DOCTYPE html>
<html>
<head>
<title>
<?php bloginfo('name');?></title>
<link rel="stylesheet" type="text/css" href="<?php bloginfo('template_directory');?>/css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="<?php bloginfo('stylesheet_url');?>">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container">
<a class="navbar-brand" href="<?php bloginfo('url');?>"><?php bloginfo('name');?></a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<?php
wp_nav_menu([
'theme_location' => 'primary',
'container' => false,
'menu_class' => 'navbar-nav mr-auto',
'depth' => 2,
'fallback_cb' => 'bs4navwalker::fallback',
'walker' => new bs4navwalker()
]);
?>
<form class="form-inline my-2 my-lg-0">
</form>
</div>
</div>
</nav>
和functions.php:
<?php
require_once('bs4navwalker.php');
function theme_setup(){
add_theme_support('post-thumbnails');
register_nav_menus(array('primary'=>__('Primary Menu')
));
}
add_action('after_setup_theme','theme_setup');