Wordpressナビバー

テンプレート

      	  <nav class="navbar navbar-default navbar-fixed-top">
    <div class="container-fluid">
      <!-- Brand and toggle get grouped for better mobile display -->
      <div class="navbar-header">
        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#topFixedNavbar1" aria-expanded="false"><span class="sr-only">Toggle navigation</span><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span></button>
        <a class="navbar-brand" href="#">Brand</a></div>
      <!-- Collect the nav links, forms, and other content for toggling -->
		<div class="collapse navbar-collapse" id="topFixedNavbar1">
<?php  
	wp_nav_menu(array(
	'theme_location' => 'navigation',
	'container' => '',
	'menu_class' => 'nav navbar-nav',
	'items_wrap' => '<ul class="nav navbar-nav">%3$s</ul>',
	'walker'=> new bootstrap_walker_nav_menu(),
						)
				  );
?>
      </div>
		<!-- /.navbar-collapse -->
    </div>
    <!-- /.container-fluid -->
  </nav>
          

functions.php

<?php

// ウィジェット
register_sidebar();

// カスタムメニュー
register_nav_menu('navigation','ナビゲーション');

class bootstrap_walker_nav_menu extends Walker_Nav_Menu {
function start_lvl( &$output, $depth ) {
    // depth dependent classes
    $indent = ( $depth > 0  ? str_repeat( "\t", $depth ) : '' ); // code indent
    // build html
    $output .= "\n" . $indent . '<ul class="dropdown-menu">' . "\n";
}
function start_el( &$output, $item, $depth, $args ) {
    global $wp_query;
    $indent = ( $depth > 0 ? str_repeat( "\t", $depth ) : '' ); // code indent
 
	$cl = ($item->url == '#') ? ' class="dropdown"':'';
 
    // build html
    $output .= $indent . '<li'.$cl.'>';
  
    // link attributes
    $attributes  = ! empty( $item->attr_title ) ? ' title="'  . esc_attr( $item->attr_title ) .'"' : '';
    $attributes .= ! empty( $item->target )     ? ' target="' . esc_attr( $item->target     ) .'"' : '';
    $attributes .= ! empty( $item->xfn )        ? ' rel="'    . esc_attr( $item->xfn        ) .'"' : '';
    $attributes .= ! empty( $item->url )        ? ' href="'   . esc_attr( $item->url        ) .'"' : '';
	if($item->url == '#') {
		 $attributes .=' class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"';
	};
//    $attributes .= ' class="menu-link ' . ( $depth > 0 ? 'sub-menu-link' : 'main-menu-link' ) . '"';
  
    $item_output = sprintf( '%1$s<a%2$s>%3$s%4$s%5$s</a>%6$s',
        $args->before,
        $attributes,
        $args->link_before,
        apply_filters( 'the_title', $item->title, $item->ID ),
        ($args->link_after).($item->url=='#')?'<span class="caret"></span>':'',
        $args->after
    );
  
    // build html
    $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
}
}

メニュー設定画面

作成されたナビメニュー