admin管理员组文章数量:1201647
so im building a custom theme and ive got stuck on the navigation
if i use wp_head(); it loads bootstrap and my custom style sheet but not the navigation if i use get_header(); it loads the navigation but not bootstrap or my custom style sheet
here is my functions.php
function register_navwalker(){
require_once get_template_directory() . '/inc/class-wp-bootstrap-navwalker.php';
}
add_action( 'after_setup_theme', 'register_navwalker' );
function wpbootstrap_enqueue_styles() {
wp_enqueue_style( 'bootstrap', '/[email protected]/dist/css/bootstrap.min.css' );
wp_enqueue_style( 'my-style', get_template_directory_uri() . '/style.css');
wp_enqueue_script('bootstrap-js', '/[email protected]/dist/js/bootstrap.bundle.min.js', array('jquery'), NULL, true);
}
add_action('wp_enqueue_scripts', 'wpbootstrap_enqueue_styles');
register_nav_menus(
array(
'main_menu'=>'Main Menu',
)
);
here is my navigation code in header.php
<nav class="navbar navbar-expand-md navbar-light bg-light" role="navigation">
<div class="container">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-controls="bs-example-navbar-collapse-1" aria-expanded="false" aria-label="<?php esc_attr_e( 'Toggle navigation', 'your-theme-slug' ); ?>">
<span class="navbar-toggler-icon"></span>
</button>
<a class="navbar-brand" href="#">Navbar</a>
<?php
wp_nav_menu( array(
'theme_location' => 'main_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(),
) );
?>
</div>
so im building a custom theme and ive got stuck on the navigation
if i use wp_head(); it loads bootstrap and my custom style sheet but not the navigation if i use get_header(); it loads the navigation but not bootstrap or my custom style sheet
here is my functions.php
function register_navwalker(){
require_once get_template_directory() . '/inc/class-wp-bootstrap-navwalker.php';
}
add_action( 'after_setup_theme', 'register_navwalker' );
function wpbootstrap_enqueue_styles() {
wp_enqueue_style( 'bootstrap', 'https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css' );
wp_enqueue_style( 'my-style', get_template_directory_uri() . '/style.css');
wp_enqueue_script('bootstrap-js', 'https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js', array('jquery'), NULL, true);
}
add_action('wp_enqueue_scripts', 'wpbootstrap_enqueue_styles');
register_nav_menus(
array(
'main_menu'=>'Main Menu',
)
);
here is my navigation code in header.php
<nav class="navbar navbar-expand-md navbar-light bg-light" role="navigation">
<div class="container">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-controls="bs-example-navbar-collapse-1" aria-expanded="false" aria-label="<?php esc_attr_e( 'Toggle navigation', 'your-theme-slug' ); ?>">
<span class="navbar-toggler-icon"></span>
</button>
<a class="navbar-brand" href="#">Navbar</a>
<?php
wp_nav_menu( array(
'theme_location' => 'main_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(),
) );
?>
</div>
Share
Improve this question
edited May 25, 2022 at 11:07
crad98
asked May 25, 2022 at 9:40
crad98crad98
52 bronze badges
2
|
1 Answer
Reset to default 0You have to call both wp_head
and get_header
.
In your header.php
, place a call to wp_head();
inside the <head>
tag, then use get_header()
inside your templates.
本文标签: phpWordPress navigation wont appear with wphead
版权声明:本文标题:php - WordPress navigation wont appear with wp_head 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738571806a2100639.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
wp_header
function in WordPress, are you sure you're callingwp_head()
in yourheader.php
? There are a handful of things that are not optional that all PHP themes must do, such aswp_head
in the header,wp_footer
in the footer, etc, you should check the theme handbook to confirm you're doing these things – Tom J Nowell ♦ Commented May 25, 2022 at 10:13