【发布时间】:2021-01-01 04:27:21
【问题描述】:
我正在尝试在 Wordpress 中将脚本和样式从 CDN 排入队列,以便可以在代码的页脚中使用此 JSfiddle:
https://jsfiddle.net/wcepbL45/
我可以看到 6 个脚本正在我的页面源中加载,但我试图嵌入页脚的 JSfiddle 不起作用。
我猜一些新脚本与原来的脚本有冲突,还是我需要在我的 footer.php 文件中加入这些脚本?
所以 atm,我的 functions.php 有这个代码:
<?php
function load_stylesheets()
{
wp_register_style('bootstrap', get_template_directory_uri() . '/css/bootstrap.min.css',
array(), false, 'all');
wp_enqueue_style('bootstrap');
wp_register_style('style', get_template_directory_uri() . '/style.css',
array(), false, 'all');
wp_enqueue_style('style');
}
add_action('wp_enqueue_scripts', 'load_stylesheets');
function include_jquery()
{
wp_deregister_script('jquery');
wp_enqueue_script('jquery', get_template_directory_uri() . '/js/jquery-3.1.3.min.js', '', 1, true);
add_action('wp_enqueue_scripts', 'jquery');
}
add_action('wp_enqueue_scripts', 'include_jquery');
function loadjs()
{
wp_register_script('customjs', get_template_directory_uri() . '/js/scripts.js', '', 1, true);
wp_enqueue_script('customjs');
}
add_action('wp_enqueue_scripts', 'loadjs');
// Next 6 styles are new (I can see them when i view page source, but I think they are clashing with something, as the JSfiddle I'm trying to input isnt working.
wp_register_style( 'Bootstrap', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css' );
wp_enqueue_style('Bootstrap');
wp_register_style( 'Bootstrap_Theme', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css' );
wp_enqueue_style('Bootstrap_Theme');
wp_register_style( 'Bootstrap_Slider', 'https://cdnjs.cloudflare.com/ajax/libs/bootstrap-slider/9.8.0/css/bootstrap-slider.min.css' );
wp_enqueue_style('Bootstrap_Slider');
wp_register_script( 'jQuery', 'https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js', null, null, true );
wp_enqueue_script('jQuery');
wp_register_script( 'Bootstrap', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js', null, null, true );
wp_enqueue_script('Bootstrap');
wp_register_script( 'Bootstrap_Slider', 'https://cdnjs.cloudflare.com/ajax/libs/bootstrap-slider/9.8.0/bootstrap-slider.min.js', null, null, true );
wp_enqueue_script('Bootstrap_Slider');
//
我哪里错了?
【问题讨论】:
-
为什么最后 6 个脚本在那些“wp_enqueue_scripts”函数之外有什么特别的原因吗?除此之外,您应该尝试在句柄前加上“thats-me”之类的前缀。如果您没有任何奇怪的缓存/缓存设置,您应该在源代码中看到这些脚本
-
嘿 Diego,我在里面试过了,但它仍然没有使范围滑块工作,它确实调整了字体大小 + 超链接颜色。所以我猜这些新的引导脚本和样式+我试图加载的jquery(使范围滑块工作)与原来的冲突?
标签: javascript php wordpress bootstrap-4 cdn