英文:
WordPress custom theme seems to load bootstrap css and JavaScript but not formatting content
问题
我正在构建一个自定义的WordPress块模板主题。我已经添加了用于加载查询的enqueue脚本,以及bootstrap和bootstrap css。在查看源代码时,它正在加载它;然而,当添加bootstrap内容和css类时,WordPress似乎忽略了设计和格式,按照WordPress的css来处理。任何帮助都将不胜感激。
网站:VoicesOfTheChurch.com
Enqueue Script:
function theme_assets() {
// Register theme stylesheet.
$theme_version = wp_get_theme()->get( 'Version' );
// CSS
wp_enqueue_style('custombootstrap', 'https:/cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css', array(), '3.4.4', 'all');
wp_enqueue_style('customstyle', get_template_directory_uri() . '/style.css', array(), '1.0.0', 'all');
// JS
wp_enqueue_script('customjquery', 'https://code.jquery.com/jquery-3.7.0.js', array(), '2.1.4', true);
wp_enqueue_script('custombootstrap', 'http://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.min.js', array(), '3.4.4', true);
}
add_action('wp_enqueue_scripts', 'theme_assets');
我添加了自定义HTML并使用了在互联网上找到的bootstrap代码来测试页面上“鞋子”所在位置的格式,以下是代码:如您所见,它根本没有格式化。这个4列部分也应该使用bootstrap进行格式化,在移动电话上缩小到4列,然后到2列,最后到单列。这也默认为正常的WordPress列格式。
<div class="container-fluid px-0">
<header>
<div class="shape"></div>
<!-- Navbar -->
<nav class="navbar fixed-top navbar-expand-lg navbar-transparent">
<a class="navbar-brand" href="#">SPORT SHOES</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">HOME <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">MEN</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">WOMEN</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">KIDS</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">BOYS</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">GIRLS</a>
</li>
</ul>
</div>
</nav>
<!-- ./ end of navbar -->
<div class="container">
<div class="row">
<div class="col-md-6 left-side">
<img src="https://i.imgur.com/jrRBTai.png" class="w-100">
</div>
<div class="col-md-6 right-side">
<h1>SPORTS SHOES</h1>
<p>FREE DELIVERY</p>
<div class="text-center">
<button class="btn order-button">ORDER NOW</button>
</div>
</div>
</div>
</div>
</header>
</div>
如果需要其他帮助,请告诉我。非常感谢您的帮助。
英文:
I am building a custom WordPress block template theme. I have added the enqueue script to load query, bootstrap is and bootstrap css. It is loading it when viewing source; however, when putting in bootstrap content and css classes, WordPress seems to be ignoring the design and formatting according to WordPress css. Any help would be greatly appreciated.
Site: VoicesOfTheChurch.com
Enqueue Script:
function theme_assets() {
// Register theme stylesheet.
$theme_version = wp_get_theme()->get( 'Version' );
//CSS
wp_enqueue_style('custombootstrap', 'https:/cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css', array(), '3.4.4', 'all');
wp_enqueue_style('customstyle', get_template_directory_uri() . '/style.css', array(), '1.0.0', 'all');
//JS
wp_enqueue_script('customjquery', 'https://code.jquery.com/jquery-3.7.0.js', array(), '2.1.4', true);
wp_enqueue_script('custombootstrap', 'http://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.min.js', array(), '3.4.4', true);
}
add_action( 'wp_enqueue_scripts', 'theme_assets' );
I added custom HTML and used a bootstrap code I found on the internet to test the formatting on the page where the “shoe” is, here is the code: As you can see, it isn’t formatting it at all. The 4 column section is supposed to be formatted with bootstrap as well where it scales down to 4 columns, to 2 columns, to single column on mobile phone. That is also defaulting to the normal WordPress column format.
<div class="container-fluid px-0"> <header> <div class="shape"></div> <!-- Navbar --> <nav class="navbar fixed-top navbar-expand-lg navbar-transparent"> <a class="navbar-brand" href="#">SPORT SHOES</a> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse" id="navbarSupportedContent"> <ul class="navbar-nav mr-auto"> <li class="nav-item active"> <a class="nav-link" href="#">HOME <span class="sr-only">(current)</span></a> </li> <li class="nav-item"> <a class="nav-link" href="#">MEN</a> </li> <li class="nav-item"> <a class="nav-link" href="#">WOMEN</a> </li> <li class="nav-item"> <a class="nav-link" href="#">KIDS</a> </li> <li class="nav-item"> <a class="nav-link" href="#">BOYS</a> </li> <li class="nav-item"> <a class="nav-link" href="#">GIRLS</a> </li> </ul> </div> </nav> <!-- ./ end of navbar --> <div class="container"> <div class="row"> <div class="col-md-6 left-side"> <img src="https://i.imgur.com/jrRBTai.png" class="w-100"> </div> <div class="col-md-6 right-side"> <h1>SPORTS SHOES</h1> <p>FREE DELIVERY</p> <div class="text-center"> <button class="btn order-button">ORDER NOW</button> </div> </div> </div> </div> </header> </div>
Anything else you need, please let me know. Any help would be appreciated.
答案1
得分: 0
我看到你的CDN链接中有一些拼写错误,请尝试以下代码:
Bootstrap样式:
wp_enqueue_style('custombootstrap', 'https://cdn.jsdelivr.net/npm/bootstrap@5.3.1/dist/css/bootstrap.min.css', array(), '5.3.1', 'all');
Bootstrap脚本:
wp_enqueue_script('custombootstrap', 'https://cdn.jsdelivr.net/npm/bootstrap@5.3.1/dist/js/bootstrap.min.js', array(), '5.3.1', true);
英文:
I see some typos in your CDN links, try out this code:
Bootstrap Style:
wp_enqueue_style('custombootstrap', 'https://cdn.jsdelivr.net/npm/bootstrap@5.3.1/dist/css/bootstrap.min.css', array(), '5.3.1', 'all');
Bootstrap Script:
wp_enqueue_script('custombootstrap', 'https://cdn.jsdelivr.net/npm/bootstrap@5.3.1/dist/js/bootstrap.min.js', array(), '5.3.1', true);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论