GithubHelp home page GithubHelp logo

andrkenya / bootstrap-5-wordpress-navbar-walker Goto Github PK

View Code? Open in Web Editor NEW

This project forked from alexweblab/bootstrap-5-wordpress-navbar-walker

0.0 0.0 0.0 20 KB

Bootstrap 5 WordPress navbar walker menu.

Home Page: https://github.com/AlexWebLab/bootstrap-5-wordpress-navbar-walker

License: MIT License

PHP 100.00%

bootstrap-5-wordpress-navbar-walker's Introduction

Bootstrap 5 WordPress navbar walker menu

bootstrap-5-wordpress-navbar-walker

How to use:

  1. Copy and paste the bootstrap_5_wp_nav_menu_walker class into the functions.php file of your theme;
  2. Register a new menu by adding the follow code into the functions.php file of your theme:
register_nav_menu('main-menu', 'Main menu');
  1. Add the following html code in your header.php file or wherever you want to place your menu:
<nav class="navbar navbar-expand-md navbar-light bg-light">
    <div class="container-fluid">
        <a class="navbar-brand" href="#">Navbar</a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#main-menu" aria-controls="main-menu" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        
        <div class="collapse navbar-collapse" id="main-menu">
            <?php
            wp_nav_menu(array(
                'theme_location' => 'main-menu',
                'container' => false,
                'menu_class' => '',
                'fallback_cb' => '__return_false',
                'items_wrap' => '<ul id="%1$s" class="navbar-nav me-auto mb-2 mb-md-0 %2$s">%3$s</ul>',
                'depth' => 2,
                'walker' => new bootstrap_5_wp_nav_menu_walker()
            ));
            ?>
        </div>
    </div>
</nav>

v1.3.0 Added support for dropdown menu (responsive) alignment: https://getbootstrap.com/docs/5.0/components/dropdowns/#menu-alignment

Here is how it works:

  • From Appearance -> Menus page of WordPress, check the CSS Classes checkbox under Screen Options;
  • Add a Custom Link with "#" in the URL field (this would be the parent of your dropdown);
  • On the CSS Classes field add any of the following alignment classes: 'dropdown-menu-start', 'dropdown-menu-end', 'dropdown-menu-sm-start', 'dropdown-menu-sm-end', 'dropdown-menu-md-start', 'dropdown-menu-md-end', 'dropdown-menu-lg-start', 'dropdown-menu-lg-end', 'dropdown-menu-xl-start', 'dropdown-menu-xl-end', 'dropdown-menu-xxl-start', 'dropdown-menu-xxl-end';
  • If any of the mentioned above class is detected, then they will automatically copied into the ul.dropdown-menu element following the Bootstrap 5 structure;
  • Any other class that is not related to the dropdown menu alignment will stay where it is.

bootstrap-5-wordpress-navbar-walker's People

Contributors

alexweblab avatar asifpix avatar justinkruit avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.