gpt4 book ai didi

php - Bootstrap 和 Wordpress 问题

转载 作者:行者123 更新时间:2023-11-28 09:09:55 25 4
gpt4 key购买 nike

它可能会像往常一样愚蠢但是..我无法让我的 style.css 或 custom.css 覆盖 Bootstrap css。我不想将我所有的自定义 css 放在我的头文件中,因为我想这不是真正的方法..

现在我尝试将它添加到我的 functions.php 中,如下所示:

    //Enqueue scripts and styles
function horizon_scripts() {
//Load the theme CSS

wp_enqueue_style( 'bootstrap', get_template_directory_uri() . '/bootstrap/css/bootstrap.min.css');
wp_enqueue_style( 'main', get_template_directory_uri() . '/style.css');

// Register the script like this for a theme:
wp_register_script( 'custom-script', get_template_directory_uri() . '/bootstrap/js/bootstrap.js', array( 'jquery' ) );

wp_register_script( 'custom-script', get_template_directory_uri() . '/bootstrap/js/bootstrap.min.js', array( 'jquery' ) );

wp_register_script( 'custom-script', get_template_directory_uri() . '/bootstrap/css/custom.css', array(), '1.0.1', 'all' );

// For either a plugin or a theme, you can then enqueue the script:
wp_enqueue_script( 'custom-script' );
}

add_action( 'wp_enqueue_scripts', 'horizon_scripts' );

所以它首先加载我的 bootstrap css,然后加载 style.css 和 custom.css,但这并没有完全成功..

因此,我们将不胜感激 :)

最佳答案

你应该使用 get_stylesheet_directory_uri() .这只是 css,没有你的 js:

function horizon_scripts() {
wp_enqueue_style( 'bootstrap', get_stylesheet_directory_uri() . '/bootstrap/css/bootstrap.min.css' );
wp_enqueue_style( 'main', get_stylesheet_uri(), array('bootstrap') );
wp_enqueue_style( 'custom', get_stylesheet_directory_uri() . '/custom.css', array('main') );
}
add_action( 'wp_enqueue_scripts', 'horizon_scripts' );

请注意,wp_enqueue_style() 的第三个参数是“dependencies”。阅读更多 in the Codex .

关于php - Bootstrap 和 Wordpress 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26545889/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com