1

enter image description hereTrying to implement wp-bootstrap-navwalker.php into my made from scratch template for wordpress.
The File for the class-wp-bootstrap-navwalker.php is located in the root directory of my theme.

functions.php

function register_navwalker()
 {
  require_once get_template_directory() . '/class-wp-bootstrap-navwalker.php';<br>
 }
add_action( 'after_setup_theme', 'register_navwalker' );

register_nav_menus( array( 'primary' => __( 'Primary Menu', 'primary' ), ) );

cover.php With the code below within the <nav> and </nav> tags

  <?php
    wp_nav_menu( array(
        'theme_location'    => 'top-menu',
        'depth'             => 2,
        'container'         => 'div',
        'container_class'   => 'collapse navbar-collapse',
        'container_id'      => 'bs-example-navbar-collapse-1',
        'menu_class'        => 'nav navbar-nav',
        'fallback_cb'       => 'WP_Bootstrap_Navwalker::fallback',
        'walker'            => new WP_Bootstrap_Navwalker(),
    ) );
    ?>

When I save changes and reload my website, I get get the wp-bootstrap-navwalker page from github.

I've checked the source of the page and see this at the footer: Fatal error: Uncaught Error: Class 'WP_Bootstrap_Navwalker' not found in C:\laragon\www\VzyulTech\wp-content\themes\Version2\index.php:17 Stack trace: #0 C:\laragon\www\VzyulTech\wp-includes\template-loader.php(106): include() #1 C:\laragon\www\VzyulTech\wp-blog-header.php(19): require_once('C:\laragon\www\...') #2 C:\laragon\www\VzyulTech\index.php(17): require('C:\laragon\www\...') #3 {main} thrown in C:\laragon\www\VzyulTech\wp-content\themes\Version2\index.php on line 17

When I check line 17 it is the 'walker' => new WP_Bootstrap_Navwalker(),

        wp_nav_menu( array(
        'theme_location'    => 'primary',
        'depth'             => 2,
        'container'         => 'div',
        'container_class'   => 'collapse navbar-collapse',
        'container_id'      => 'bs-example-navbar-collapse-1',
        'menu_class'        => 'nav navbar-nav',
        'fallback_cb'       => 'WP_Bootstrap_Navwalker::fallback',
        'walker'            => new WP_Bootstrap_Navwalker(),
    ) );

any help is much appreciated.

2

Your register_navwalker function is loading navwalker with this line:

require_once get_template_directory() . './class-wp-bootstrap-navwalker.php';

where you concatenate the path of the theme with this string:

'./class-wp-bootstrap-navwalker.php'

and the dot there at the beginning is a problem. The result would look like this:

DOMAIN/wp-content/themes/THEME./class-wp-bootstrap-navwalker.php

remove the dot and it should find and load the script.

EDIT:

Also you shouldn't change your original post or question, but add to it. Otherwise comments and answers might not make sense anymore.

0

Place class-wp-bootstrap-navwalker.php in your WordPress theme folder /wp-content/your-theme/

Open your WordPress themes functions.php file - /wp-content/your-theme/functions.php - and add the following code:

If you encounter errors with the above code use a check like this to return clean errors to help diagnose the problem.

    function register_navwalker()
    {
       if ( ! file_exists( get_template_directory() . '/class-wp-bootstrap-navwalker.php' ) ) {
       // file does not exist... return an error.
       return new WP_Error( 'class-wp-bootstrap-navwalker-missing', __( 'It appears the class-wp-bootstrap-navwalker.php file may be missing.', 'wp-bootstrap-navwalker' ) );
      } else {
        // file exists... require it.
        require_once get_template_directory . '/class-wp-bootstrap-navwalker.php';
    }
  } 
  add_action( 'after_setup_theme', 'register_navwalker' );

You will also need to declare a new menu in your functions.php file if one doesn’t already exist.

register_nav_menus( array(
    'top-menu' => __( 'Top Menu', 'THEMENAME' ),
) );

Usage : Add or update any wp_nav_menu() functions in your theme (often found in header.php) to use the new walker by adding a 'walker' item to the wp_nav_menu args array.

   <?php
wp_nav_menu( array(
    'theme_location'    => 'top-menu',
    'depth'             => 2,
    'container'         => 'div',
    'container_class'   => 'collapse navbar-collapse',
    'container_id'      => 'bs-example-navbar-collapse-1',
    'menu_class'        => 'nav navbar-nav',
    'fallback_cb'       => 'WP_Bootstrap_Navwalker::fallback',
    'walker'            => new WP_Bootstrap_Navwalker(),
) );
?>
0

My apoligies, I have been able to resolve the problem.

What I did wrong was go to: https://github.com/wp-bootstrap/wp-bootstrap-navwalker and on the php file for the wp-bootstrap-navwalker.php, i had right click and saved the file. I then opened the the file in a notepad and noticed it began with:

<!DOCTYPE html>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.