The theme I am creating is not working correctly. The menu is not collapsing into mobile view with the hamburger icon when I decrease screen size. I can see all the classes when using the inspect tool on Chrome.
What I have tried:
- Compared the code to a theme I made as exercise and it looks exactly the same.
- Pasted the navbar example from bootstrap directly and tested(didn't collapse either).
- Used the links on bootstrap like https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css and https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js to make use of the styling and functionality.
- Downloaded the bootstrap files and linked it locally.
Please see my header.php and functions.php below:
Header.php
<!DOCTYPE html> <head> <title></title> <?php wp_head(); ?> </head> <body <?php body_class(); ?>> <nav class="navbar navbar-default navbar-fixed-top <?php admin_bar_menu(); ?>"> <div class="container-fluid menu-container"> <!-- 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" 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 esc_url( home_url('/')); ?>"><?php bloginfo( 'name' ); ?></a> </div> <!-- Collect the nav links, forms, and other content for toggling --> <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> <?php wp_nav_menu(array( 'theme_location' => 'primary', 'menu_class' => 'nav navbar-nav navbar-right', 'fallback_cb' => false )); ?> </div> </div> </nav> Functions.php
<?php function winetours_scripts() { wp_enqueue_script( "bootstrap-js", get_template_directory_uri() . "/bootstrap/js/bootstrap.min.js", array("jquery") ); wp_enqueue_style( "bootstrap", get_template_directory_uri() . "/bootstrap/css/bootstrap.min.css"); wp_enqueue_style( "winetour-style" , get_stylesheet_uri() ); } add_action("wp_enqueue_scripts", "winetours_scripts"); function winetours_setup() { register_nav_menus( array( "primary" => "Primary Menu", "winetour" )); //Add theme support for document title tag add_theme_support( "title-tag" ); } add_action( "after_setup_theme", "winetours_setup"); //Adds the padding to the top of menu for logged in with toolbar function admin_bar_menu() { if ( is_user_logged_in() ){ $current_user = wp_get_current_user(); if (user_can( $current_user, 'administrator' )) { echo "admin-nav"; } } }