Bootstrap CDN + WP // 如何编辑'.css'

Bootstrap CDN + WP // How to edit '.css’

我正在 Wordpress + Bootstrap CDN 上构建我的网站。 我决定把它放到 CDN 上,这样以后更新就没有问题了,而且我读到这样速度更快。

所以问题是我的样式有问题。 我将我本地的‘style.css’导入到‘header.php’,但是由于 CDN 的‘bootstrap.min.css’也有它自己的参数,我无法应用一些东西。

如何改写CDN的参数?或者有没有办法编辑这个确切的“bootstrap.min.css”文件?

提前致谢。

@TylerH 回答了我的问题,解决了我的问题。

A better technique would be to include your own CSS file after you include the CDN file, and just write whichever styles you need to this CSS file of yours. That way they will override the problematic styles in your CDN file.

非常感谢!

您只需使用 wp_enqueue_style 即可加载这些文件。这是您可以从中获得灵感的示例。

function enqueue_my_scripts() {
wp_enqueue_script( 'jquery', '//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js', array('jquery'), '1.9.1', true); // we need the jquery library for bootsrap js to function
wp_enqueue_script( 'bootstrap-js', '//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js', array('jquery'), true); // all the bootstrap javascript goodness
}
add_action('wp_enqueue_scripts', 'enqueue_my_scripts');


function enqueue_my_styles() {
wp_enqueue_style( 'bootstrap', '//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css' );
wp_enqueue_style( 'my-style', get_template_directory_uri() . '/style.css');
}
add_action('wp_enqueue_scripts', 'enqueue_my_styles');

要编写规则,只需在 style.css 文件中使用 !important

当您使用 wp_enqueue_style 时,您可以选择控制在何处使用您的样式和脚本以供进一步参考。这是一个如何使用它的例子。

function my_enqueue_stuff() {
  if ( is_page( 'landing-page-template-one' ) ) {
    /** Call landing-page-template-one enqueue */
  } else {
    /** Call regular enqueue */
  }
}
add_action( 'wp_enqueue_scripts', 'my_enqueue_stuff' );