首页 > 解决方案 > Bootstrap 下拉菜单不显示 Wordpress 下拉菜单中的项目

问题描述

我正在开发一个子主题,并在我的主题的通用 wp_enqueue_style 之前将 Bootstrap 添加到 functions.php 中,如下所示:

if ( ! function_exists( 'ghostpool_enqueue_child_styles' ) ) {
    function ghostpool_enqueue_child_styles() { 
        wp_enqueue_script( 'bootstrap_js', 'https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js', array('jquery'), NULL, true );
        
        wp_enqueue_style( 'bootstrap_css', 'https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css', false, NULL, 'all' );
        
        wp_enqueue_style( 'ghostpool-style', get_template_directory_uri() . '/style.css', array(), AARDVARK_THEME_VERSION );
        wp_enqueue_style( 'ghostpool-child-style', get_stylesheet_directory_uri() . '/style.css', array( 'ghostpool-style' ), AARDVARK_THEME_VERSION );
        wp_style_add_data( 'ghostpool-child-style', 'rtl', 'replace' );
    }
}
add_action( 'wp_enqueue_scripts', 'ghostpool_enqueue_child_styles' );

然后我在一行中添加了原始 HTML,每列有 4 列,如下所示:

<div class="dropdown">
  <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
    CHOOSE A GENRE
  </button>
  <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
    <a class="dropdown-item" href="#">Action</a>
    <a class="dropdown-item" href="#">Another action</a>
    <a class="dropdown-item" href="#">Something else here</a>
  </div>
</div>

我的下拉按钮显示正确,但是当我单击它们时,它们不显示下拉列表中的内容?我是否忘记在functions.php中添加任何特殊的js?我错过了什么吗?

标签: phpcsswordpressbootstrap-4dropdown

解决方案


推荐阅读