【发布时间】:2015-08-21 08:33:01
【问题描述】:
我在 Google 上读到 CDN 链接更适合使用,因为它具有速度和额外的安全层。我是 WordPress 开发的新手。我将 CDN 链接放在一个 JS 文件中并入队。但是,它没有在我的网站上生效。
custom-js.js
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
functions.php
<?php
function load_css_js() {
wp_register_style( 'child-css', get_stylesheet_directory_uri() . '/style.css', false, NULL, 'all' );
wp_enqueue_style( 'child-css' );
wp_register_script( 'child-js', get_stylesheet_directory_uri() . '/js/custom-js.js', array( 'jquery' ), NULL, false );
wp_enqueue_script( 'child-js' );
}
add_action( 'wp_enqueue_scripts', 'load_css_js' );
?>
【问题讨论】:
-
那么生成的 html 中会显示什么?
-
@MarcB 只是 HTML,没有花哨的 Bootstrap 元素。没有颜色,没有整洁的按钮,等等……很普通
-
你是不是把这些链接加到了一个js文件里?它们属于您的 html
-
请在 SSCC 示例中附加生成的 HTML 和您的 JS 文件。见sscce.org 和jsfiddle.net
-
"以及额外的安全层" --- 怎么样?实际上恰恰相反。
标签: javascript php wordpress twitter-bootstrap cdn