Wordpress Menu hickup - php

At the moment i am converting my HTML to Wordpress. No matter what i try i can't seem to get my menu look the same in
Wordpress as it does in HTML. The CSS is correct (did allot of troubleshooting to root that out). This is the HTML:
<div class="navbar-wrapper">
<div class="navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only"> Toggle navigation </span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/"><img src="assets/img/Logo%20BY.png" alt="Logo" height="75" width="75"></a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li class="active">Home</li>
<li>Onze diensten</li>
<li>Blog</li>
<li>Contact</li>
</ul>
</div>
</div>
</div>
</div>
And this is the Wordpress way i am trying to implement:
<div class="navbar-wrapper">
<div class="navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only"> Toggle navigation </span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">
<img src="<?php bloginfo('stylesheet_directory'); ?>/assets/img/Logo%20BY.png" alt="Logo" height="75" width="75">
</a>
</div>
<?php
wp_nav_menu( array(
'theme_location' => 'primary',
'container' => 'nav',
'container_class' => 'navbar-collapse collapse',
'menu_class' => 'nav navbar-nav navbar-right'
));
?>
</div>
</div>
</div>
Thanks in advance for the help!

I suspect you are missing the container div. Right click and inspect on the badly formatted menu and see if the (container) div is there
<div class="navbar-collapse collapse">
You have
'container' => 'nav'
should be
'container' => 'div'

Related

Two menus in the same navbar?

I would like to add a dropdown menu at the right side of my menu. When I declare a second menu with a new navwalker, nothing loads anymore and my site stays white (blank).
Here is my header
<nav class="navbar navbar-inverse">
<div class="col-md-10">
<div class="container">
<div class="row">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed col-md-12 col-lg-12 col-xs-12 col-sm-12" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
</div>
<div id="navbar" class="navbar-collapse collapse">
<div class="container">
<div class="colum-lg-12 col-md-12 ">
<?php bootstrap_nav(); ?>
</div>
</div>
<!--/.nav-collapse -->
</div>
<!--/.container-fluid -->
</nav>
</header>
<!-- #masthead -->
</div>
</div>
<div id="content" class="site-content">
And here is my function.php
function bootstrap_nav()
{
wp_nav_menu( array(
'theme_location' => 'header-menu',
'depth' => 2,
'container' => 'false',
'menu_class' => 'nav navbar-nav',
'fallback_cb' => 'wp_bootstrap_navwalker::fallback',
'walker' => new wp_bootstrap_navwalker())
);
}
You don't need to add a walker class unless you need to customize the second menu.
Follow the documentation here : Link
wp_nav_menu(array('menu_id'=>'your_menu_id'));
Add extra arguments as you need and place the menu directly to the right side div.

Bootstrap navigation hamburger on symbol functionality

I have used Bootstrap menu, I cant seem to see why the hamburger drop-down in not functioning.
at the moment the full menu is expanded on mobile and the hamburger symbol has not functionality, im not sure what has gone wrong in the code
Full code HTMl
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container" style="height: 63px;">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bootstrap-navbar-collapse-1"
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="<?php echo get_page_link(2); ?>">
<img src="<?php bloginfo('url'); ?>/wp-content/uploads/2016/10/logo.png">
</a>
<button type="button" class="btn button-primary-signup navbar-btn navbar-right hidden-xs">
Sign up
</button>
<button type="button" class="login-button btn btn-link navbar-btn navbar-right hidden-xs">
Login
</button>
</div>
<div id="navbar" style="background-color: #333;max-height: 44px;">
<div class="container">
<?php bootstrap_megamenu_nav(); ?>
</div>
</div>
</nav>
function php
function bootstrap_megamenu_nav()
{
wp_nav_menu(array(
'theme_location' => 'locations-primary',
'depth' => 4,
'container' => 'div',
'container_class' => 'collapse navbar-collapse',
'container_id' => 'bootstrap-navbar-collapse-1',
'menu_class' => 'nav navbar-nav yamm navbar-main-head',
'fallback_cb' => 'Yamm_Nav_Walker_menu_fallback',
'walker' => new Yamm_Nav_Walker())
);
}
There is no target with id="bootstrap-navbar-collapse-1".
The collapsible nav items are supposed to be contained in a collapse element.
See the Bootstrap docs for an example:
http://getbootstrap.com/components/#navbar-default

Convert static navbar into WordPress Header

I am learning to build wordpress themes. i have created a static html website. now I am trying to convert it into a wordpress theme. First, i need to convert the static navbar into a dynamic one. The following is my header.php code:
<!-- NAVIGATION -->
<nav class="navbar navbar-fixed-top navbar-inverse">
<div class="container">
<div class="row">
<div class="col-sm-8">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<!-- navbar-header -->
<?php
wp_nav_menu( array(
'theme_location' => 'primary',
'container' => 'nav',
'container_class' => 'collapse navbar-collapse navigation',
'menu_class' => 'nav navbar-nav'
)
);
?>
</div>
<!-- .col-sm-8 -->
<div class="col-sm-4 navigation" id="social-icons">
<ul>
<i class="fa fa-facebook"></i>
<i class="fa fa-twitter"></i>
<i class="fa fa-instagram"></i>
<i class="fa fa-pinterest"></i>
<i class="fa fa-heart"></i>
<i class="fa fa-google-plus"></i>
<i class="fa fa-tumblr"></i>
</ul>
</div>
<!-- social-icons -->
</div>
<!-- row -->
</div>
<!-- .container -->
</nav>
<!-- .navbar -->
But the output of this is:
Whereas the static one looks like:
JS Fiddle for the Static website: https://jsfiddle.net/9yyrnmuy/7/
EDIT 1:
I inspected to check whether the classes are being over ridden and found the following syntax:
<div class="container">
<div class="row">
<div class="col-sm-8">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<!-- navbar-header -->
<nav class="nav navbar-nav">
<ul>
<li class="page_item page-item-7 current_page_item">
<a>Home</a></li>
</ul>
</nav>
</div>
<!-- .col-sm-8 -->
whereas I want it to be:
<div class="container">
<div class="row">
<div class="col-sm-8">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<!-- navbar-header -->
<nav class="collapse navbar-collapse navigation" id="navbar-collapse">
<ul class="nav navbar-nav">
<li>Home</li>
<li>Category 1</li>
<li>Category 2</li>
<li>Category 3</li>
<li>About</li>
<li>Contact Me</li>
</ul>
<!-- .navbar-nav -->
</nav>
<!-- #navbar-collapse -->
</div>
<!-- .col-sm-8 -->
Can anyone please help to solve this issue? Any help will be appreciated.

Bootstrap mobile menu doesn't show in wordpress

I have created a bootstrap theme for my wordpress website but the mobile menu doesn't show up when I make my browser window smaller
I've tried everything on stackoverflow so far, but whenever I try out another menu code, my menu gets tiny and pulled to the right side of my browser window. I don't know what the problem is.
Here's my menu code:
<body <?php body_class(); ?>>
<?php if ( is_front_page() ) { ?>
<nav class="navbar navbar-home navbar-static-top" role="navigation">
<div class="container">
<!-- Mobile display -->
<div class="navbar-header">
<a class="navbar-brand" href="<?php echo home_url(); ?>"><img src="http://localhost:8888/wp-content/uploads/2016/01/proformat_logotypewhite#2x.png" height="20" width="157"></a>
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="navbar-ex1-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<!-- Collect the nav links for toggling -->
<?php // Loading WordPress Custom Menu
wp_nav_menu( array(
'container_class' => 'collapse navbar-collapse navbar-ex1-collapse',
'container_id' => 'navbar-ex1-collapse',
'menu_class' => 'nav navbar-nav pull-right',
'menu_id' => 'main-menu',
'walker' => new Cwd_wp_bootstrapwp_Walker_Nav_Menu()
) );
?>
</nav>
<div class="fullscreen-bg">
<div class="hometext">
<h1 style="color: #ffffff;">VI ÄLSKAR BILDER.</h1>
<h4 style="color: #ffffff;">Vi gör tavlor på en mängd olika vis. Komponera din egen kombination av material och bearbetning eller välj bland våra färdiga lösningar.</h4>
</div>
<span class="read-more-container"><a class="scroll" href="#start">LÄS MER<br><img src="http://localhost:8888/wp-content/uploads/2016/01/arrowdown.png" style="max-width: 50px;"/></a></span>
</div>
<?php } else { ?>
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<!-- Mobile display -->
<div class="navbar-header">
<a class="navbar-brand" href="<?php echo home_url(); ?>"><img src="http://localhost:8888/wp-content/uploads/2015/10/proformat_logotype#2x.png" height="20" width="157"></a>
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<!-- Collect the nav links for toggling -->
<?php // Loading WordPress Custom Menu
wp_nav_menu( array(
'container_class' => 'collapse navbar-collapse navbar-ex1-collapse',
'menu_class' => 'nav navbar-nav pull-right',
'menu_id' => 'main-menu',
'walker' => new Cwd_wp_bootstrapwp_Walker_Nav_Menu()
) );
?>
</nav>
I have two different menus on my website. One that is showing only on the front page, and another one on every other page. (they have different colors and logotypes)
EDIT:
The HTML code that is being rendered:
<nav class="navbar navbar-home navbar-static-top" role="navigation">
<div class="container">
<!-- Mobile display -->
<div class="navbar-header">
<a class="navbar-brand" href="http://localhost:8888"><img src="http://localhost:8888/wp-content/uploads/2016/01/proformat_logotypewhite#2x.png" height="20" width="157"></a>
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="navbar-ex1-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<!-- Collect the nav links for toggling -->
<div id="navbar-ex1-collapse" class="collapse navbar-collapse navbar-ex1-collapse"><ul id="main-menu" class="nav navbar-nav pull-right"><li id="menu-item-394" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-394">MATERIAL</li>
<li id="menu-item-393" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-393">BEARBETNING</li>
<li id="menu-item-392" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-392">BILDTJÄNSTER</li>
<li id="menu-item-115" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-115">KONTAKT</li>
</ul></div>
</nav>
You need to add navbar-default (or navbar-inverse) to
<nav class="navbar navbar-default navbar-home navbar-static-top" role="navigation">
You can then use your custom navbar-home class to override the styles/colors. Or, if you are compiling the boostrap .less yourself, you can play with the colors for all the navigation/hover states in variables.less.
I would personally apply navbar-default to your homepage navigation and navbar-inverse to your internal page navigation and play with colors & styling from there, removing the need for the additional classes at all.
http://codepen.io/anon/pen/jWZXvZ
Extras:
You are also missing a closing container div tag
You can use .navbar-right on the .navbar-collapse div.
You will need to make sure you are loading jquery and then bootstrap's JS for the toggle functionality.

Making active link with php and bootstrap

I need a little help with my code. I'm using bootstrap and i have 3 links for now and i want them to be active as i click on them. I tried many ways to do that but i failed.
Here is my code:
<nav class="navbar navbar-default">
<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="#bs-example-navbar-collapse-1">
<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="index.php">POSLOVNA STATISTIKA</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active">Poslovni korisnici <span class="sr-only">(current)</span></li>
<li>Korisnici</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
<ul class="nav navbar-nav">
<li <?php if(isset($_GET['poslovni_korisnici'])){ echo 'class="active"'; } ?>>Poslovni korisnici <span class="sr-only">(current)</span></li>
<li <?php if(isset($_GET['korisnici'])){ echo 'class="active"'; } ?>Korisnici</li>
</ul>

Categories