• Resolved erwindemoel

    (@erwindemoel)


    I’m trying to create a Walker class to style my top main menu bar. I’m following this guide and code sample:
    https://www.youtube.com/watch?v=ArEmwJV6M7s
    https://github.com/Alecaddd/WordPress101/blob/master/lesson_14/inc/walker.php

    When I implement it on my website using below code snippets, I consitently get the following error:

    enter image description here

    English translation from Dutch:
    “A critical error has occurred on this site. Check your site administrator email inbox for instructions. Learn more about troubleshooting issues in WordPress.”

    Code

    functions.php

    require get_template_directory() . '/inc/walker.php';

    walker.php

    <?php
    /* Collection of Walker classes */
    
    class MeterInsight_Menu_Walker extends Walker_Nav_Menu {
        function start_lvl(&$output, $depth=0, $args=null) { //ul
            $indent = str_repeat("\t",$depth);
            $submenu = ($depth > 0) ? ' sub-menu' : '';
            $output .= "\n$indent<ul class=\"dropdown-menu$submenu depth_$depth\">\n";
        }
    
        function start_el(&$output, $item, $depth=0, $args=[], $id=0) {
        }
    
        function end_el() {
        }
    
        function end_lvl() {
        }
    }
    ?>

    menu.php:

    <?php
    wp_nav_menu(
        array(
            'theme_location' => 'primary',
            'menu_class' => 'navbar-nav ms-auto',
            'container' => 'nav',
            'container_class' => 'collapse navbar-collapse',
            'menu' => 'primary',
            'walker' => new MeterInsight_Menu_Walker()
        )
    );
    ?>

    How can I fix this? Or where can I get a more elaborate error message?

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Creating Walker class to style main menu bar gives unknown error’ is closed to new replies.