Like Bootstrap, BootScore only knows menus with a depth of 2. Bootstrap because it wants to in principle. BootScore because it follows its base as strictly as possible. Level 0 entries are listed horizontally in the header, and the corresponding level 1 entries are listed vertically below. Thus, the top-level entries group the entries below them. And menus behave the same way on smartphones and desktops.We want to talk a about deeper nested menus, here:
That means, that the top menu items are clicked when the corresponding subgroup is to be displayed. And they are also clicked to collapse the group again. Without any hover
effect, neither on smartphones nor on larger devices. Here we show a solution for creating multidimensional menus (indirectly) offered by BootScore itself:
Solution
- Inside your theme directory, create an include directory named
inc
. - Download navbar.php from github.com/imanishpushkar/bs5-navwalker into that
inc
- directory. - Rename that file to
class-bootstrap-5-navwalker.php
- Add the following code to the
functions.php
file in your child theme folder:
// Register new 3 level depth nav-walker
function register_navwalker() {
require_once('inc/class-bootstrap-5-navwalker.php');
// Register Menus
register_nav_menu('main-menu', 'Main menu');
register_nav_menu('footer-menu', 'Footer menu');
}
- Copy — if not already done — the file
header.php
from the themebootscore-main
into your child theme. - Inside
header.php
, look forwp_nav_menu(array(
… - In that array, increase
'depth' => 2,
up to the maximum depth your menu has.
Background
Let’s consider the aspects backward this time:
- The code from the GitHub repository bs5-navwalker by Manisch Pushkar is explicitly MIT licensed. So you can incorporate it directly into your child-theme without undermining its open source nature.
- The solution itself has been offered by Bastian Kreiter1 in a discussion2 as a way out for bootScore preferring to follow the peculiarities of Bootstrap this time.
- The fact that Bootstrap should offer multidimensional (= nested) menus is discussed again and again.3 And rejected, for different reasons: Mark Otto4 had already — as he said in 2017 — rejected this wish three years ago. And that had prevented no one from writing good sites.5 Besides, there would be only difficult technical solutions, where effort and profit would not be in reasonable proportion.6
Thus, we now have a solution at hand for her desire for deeper embedded submenus. Nevertheless, we should focus on ourselves. Because Mark’s objections in terms of usability and design have to be considered too.
And finally, still this:
- The submenus are superimposed here by a click and must — according to the bootStrap logic — be actively clicked away again. So the way described here does not (yet) cover a solution for a missing
hover
effect on desktop systems.7. - The fact that submenus must always be opened and closed again by clicking is contrary to the common practice of assigning a page directly to the grouping menu item. The menu design must take this into consideration.8.
And how does this …
… support our migration to bootScore? Well, once a web designer has taken the first general steps and has checked SEO, she will soon turn to a really thick board, her properly clustered and presented menu without getting too fancy. Eventually, she is going to spruce and speed up the display of fixed and scalable images. This post talks about a part of this way.
- = crftwrk, the spiritus rector of bootScore [↩]
- cf. discussion #347 [↩]
- pars pro toto: cf. issue 27659 [↩]
- = mdo, the spiritus rector of Bootstrap [↩]
- cf. 21026#issuecomment-313980746 [↩]
- cf. 27659#issuecomment-441783535 [↩]
- More about hover menus later [↩]
- More about grouping sub menus later [↩]