[英]Bootstrap 5 and wordpress navbar-walker
I am trying for the first time to integrate Bootstrap 5.2 in a wordpress site (it is just a local test).我第一次尝试在 wordpress 站点中集成 Bootstrap 5.2(这只是一个本地测试)。 I am doing it through this wp-bootstrap-walker I found: https://github.com/wp-bootstrap/wp-bootstrap-navwalker/
我正在通过我发现的这个 wp-bootstrap-walker 来做到这一点: https://github.com/wp-bootstrap/wp-bootstrap-navwalker/
I added the '/class-wp-bootstrap-navwalker.php'file the functions it says in the installation guide to the functions.php:我在“/class-wp-bootstrap-navwalker.php”文件中添加了它在函数安装指南中所说的函数。php:
function register_navwalker(){
require_once get_template_directory() . '/class-wp-bootstrap-navwalker.php';
}
add_action( 'after_setup_theme', 'register_navwalker' );
register_nav_menus( array(
'primary' => __( 'Main header menu', 'mytheme' ),
) );
I also changed this in order to use the 5th version:为了使用第 5 个版本,我也改变了这个:
'walker' => new WP_Bootstrap_Navwalker(),
+ 'walker' => 'WP_Bootstrap_Navwalker',
So till here there is no error displayed, also in the WordPress back end I can select the 'Main header menu' menu defined in the functions.php, the problem is when I select this option and I go to the main page, then everything crashes:所以直到这里没有显示错误,同样在 WordPress 后端我可以 select 功能中定义的“主 header 菜单”菜单。php,问题是当我 select 这个选项和我 88306030 一切到 677488 主页,崩溃:
: Uncaught Error: Call to a member function walk() on string in C:\laragon\www\mydirectory\wp-includes\nav-menu-template.php:622 Stack trace: #0 C:\laragon\www\mydirectory\wp-includes\nav-menu-template.php(242): walk_nav_menu_tree(Array, 2, Object(stdClass)) #1 C:\laragon\www\mydirectory\wp-content\themes\my-theme\header.php(61): wp_nav_menu(Object(stdClass)) #2 C:\laragon\www\mydirectory\wp-includes\template.php(783): require_once('C:\\laragon\\www\\...') #3 C:\laragon\www\mydirectory\wp-includes\template.php(718): load_template('C:\\laragon\\www\\...', true, Array) #4 C:\laragon\www\mydirectory\wp-includes\general-template.php(48): locate_template(Array, true, true, Array) #5 C:\laragon\www\mydirectory\wp-content\themes\my-theme\index.php(8): get_header() #6 C:\laragon\www\mydirectory\wp-includes\template-loader.php(106): include('C:\\laragon\\www\\...') #7 C:\laragon\www\mydirectory\wp-blog-header.php(19): require_once('C:\\laragon\\www\\...') #8 C:\laragon\www\mydirectory\index.php(17): require('C:\\laragon\\www\\...') #9 {main} thrown in
I solve it writing this:我解决它写这个:
function register_navwalker(){
require_once get_template_directory() . '/class-wp-bootstrap-navwalker.php';
}
add_action( 'init', 'register_navwalker' );
I wrote init instead after_setup_theme to execute the function, also with wp_loaded works well.我写了init而不是after_setup_theme来执行 function, wp_loaded也运行良好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.