admin管理员组文章数量:1323353
Trying 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.
Trying 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.
Share Improve this question edited Sep 9, 2020 at 22:12 rolliefngrz asked Sep 9, 2020 at 3:42 rolliefngrzrolliefngrz 113 bronze badges3 Answers
Reset to default 2Your 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.
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(),
) );
?>
My apoligies, I have been able to resolve the problem.
What I did wrong was go to: https://github/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>
本文标签: menusbootstrapnavwalker will not load
版权声明:本文标题:menus - bootstrap-navwalker will not load 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742128782a2422064.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论