使用functions.php将引导程序启动到WordPress



我在我的functions.php文件夹中具有以下代码(使用子主题,如果在这里进行任何因素)

<?php
function theme_styles() {
    wp_enqueue_style( 'bootstrap_css', get_template_directory_uri() . '/bootstrap.min.css' );
    wp_enqueue_style( 'main_css', get_template_directory_uri() . '/style.css' );
}
add_action( 'wp_enqueue_scripts', 'theme_styles');
function theme_js() {
    global $wp_scripts;
    wp_enqueue_script( 'bootstrap_js', get_template_directory_uri() . '/bootstrap.min.js' );
}
add_action( 'wp_enqueue_scripts', 'theme_js');
?>

使用FTP,我添加了Bootstrap.min.css和Bootstrap.min.js文件夹中的我的子主题目录(从网站下载)。

但是,当我去我正在构建的页面中的代码块上进行手风琴时,它不会创建手风琴。代码如下:

<div id="accordion" class="panel-group">
    <div class="panel panel-default">
        <div class="panel-heading">
            <h4 class="panel-title">
                <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">1. What is HTML?</a>
            </h4>
        </div></div></div>

所有发生的就是用链接显示文本。

我做错了什么?

get_template_directory_uri()返回父主题的目录。为了获得子主题目录,您应该使用get_stylesheet_directory_uri()

注意: get_stylesheet_directory_uri()不包含落后斜线。

因此,在您的wp_enqueue_*行中,get_stylesheet_directory_uri()交换get_template_directory_uri(),只要文件路径的其余部分正确,并且该文件确实在服务器上。

最新更新