【问题标题】:Bootstrap & Wordpress issueBootstrap 和 Wordpress 问题
【发布时间】:2014-10-24 18:26:11
【问题描述】:

它可能会像往常一样愚蠢,但是.. 我无法让我的 style.css 或 custom.css 覆盖引导 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' );

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

所以任何帮助将不胜感激:)

【问题讨论】:

  • 刚试了,还是不行

标签: php html css wordpress twitter-bootstrap


【解决方案1】:

您应该使用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

【讨论】:

  • 非常感谢,终于搞定了。谷歌这次没有帮助我,但你做到了:D
猜你喜欢
  • 1970-01-01
  • 2020-03-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多