我正在制作我的第一个自定义wordpress主题,我遇到了函数。php的问题
我也使用bootstrap,所以我想包括bootstrap样式表到wp我目前这样做-:
style.css
@import url('css/bootstrap.css');
@import url('css/font-awesome.css');
我知道我可以使用functions.php做同样的事情,所以我写了一个自定义函数,并试图这样做-:
functions.php
<?php
/* Theme setup */
require_once('wp_bootstrap_navwalker.php');
/* Add bootstrap support to the Wordpress theme*/
function theme_add_bootstrap() {
wp_enqueue_style( 'bootstrap-css', get_template_directory_uri().'/css/bootstrap.css' );
wp_enqueue_style( 'style-css', get_template_directory_uri().'/css/font-awesome.css' );
wp_enqueue_script( 'bootstrap-js', get_template_directory_uri().'/js/bootstrap.js', array(), '3.0.0', true );
}
add_action( 'wp_enqueue_scripts', 'theme_add_bootstrap' );
?>
这似乎不起作用。functions.php也不加载wp jquery或bootstrap.js
有谁能给我解释一下这件事吗?我将永远感激不尽。这不是子主题,而是自定义主题。在进入队列之前尝试注册脚本。例如:
function my_enqueue_scripts() {
// Register Bootstrap JS.
wp_register_script( 'bootstrap-js', get_template_directory_uri() . '/js/bootstrap.min.js', array( 'jquery' ), NULL, true );
// Enqueue Bootstrap JS.
wp_enqueue_script( 'bootstrap-js' );
}
add_action( 'wp_enqueue_scripts', 'my_enqueue_scripts' );