Anvendelse af nav-walker.
Hent class-wp-bootstrap-navwalker.php og husk bootstrap, popper og jquery skal være indlæst.
//Tilføj menu i wordpress menu
add_theme_support('menus');
//Tilføj menu på sider - lokationer
register_nav_menus(
array(
'header-menu' => __('Header Menu', 'theme'),
'footer-menu' => __('Footer Menu', 'theme'),
));
// Tilføj Bootstrap Navigation Walker
require_once get_template_directory() . '/class-wp-bootstrap-navwalker.php';
<nav class="navbar navbar-expand-lg navbar-light bg-light" role="navigation">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-controls="bs-example-navbar-collapse-1" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<a class="navbar-brand" href="<?php bloginfo( 'url' ); ?>">
<!-- Indsætter logo, hvis valgt i wordpress mennu -->
<?php
$custom_logo_id = get_theme_mod( 'custom_logo' );
$logo = wp_get_attachment_image_src( $custom_logo_id , 'full' );
if ( has_custom_logo() ) {
echo '<img src="' . esc_url( $logo[0]) . '" alt="' . get_bloginfo( 'name' ) . '">';
} else {
echo '<h3>'. get_bloginfo( 'name' ) .'</h3>';
}
?>
</a>
<?php
wp_nav_menu( array(
'theme_location' => 'header-menu',
'depth' => 2,
'container' => 'div',
'container_class' => 'collapse navbar-collapse',
'container_id' => 'bs-example-navbar-collapse-1',
'menu_class' => 'nav navbar-nav', //navigation
'fallback_cb' => 'WP_Bootstrap_Navwalker::fallback',
'walker' => new WP_Bootstrap_Navwalker(),
) );
?>
</div>
</nav>