我在下面创建了一个儿童主题wp-content/themes/my-theme
目前有5个文件:
|-my-theme
|----assets
|--------css
|------------bootstrap.min.css
|--------js
|------------bootstrap.min.js
|----functions.php
|----index.php
|----style.css
现在问题在我的functions.php
文件,我已尝试添加.css
和.js
文件如下:<?php
# functions.php
/**
* add css | js files to WP
*/
function theme_asset_setup()
{
# styles
wp_enqueue_style(\'bootstrap\', get_template_directory_uri(). \'/assets/css/bootstrap.min.css\', []);
# scripts
wp_enqueue_script(\'bootstrap\', get_template_directory_uri(). \'/assets/js/bootstrap.min.js\', []);
}
/** actions **/
add_action(\'wp_enqueue_scripts\', \'theme_asset_setup\');
这一半就可以了。这将添加我的.js
和.css
具有此路径的文件:http://site.local/wp-content/themes/twentynineteen/assets/css/bootstrap.min.css?ver=5.1
我的父主题是twentynineteen
如我的style.css
文件:/*
Theme Name: My Theme
Author: treybake
Description: foobar
Requires at Least: WordPress 4.9.6
Version: 0.1
License: GNU General Public License v2 or later
Text Domain: my-theme
Template: twentynineteen
*/
所以我猜这是我.css
和.js
- 但我不知道如何进一步调试。为什么我的css/js文件会忽略我的子主题路径?
谢谢