javascript - 在 Wordpress 中排队外部 JS 和 CSS

标签 javascript jquery css wordpress enqueue

我在使用我的新网站时遇到了一些困难。

2 确实有问题。

首先是调用外部 JS 和 CSS 脚本。我已将它们添加到我的 functions.php 文件中,我的所有其他网站都采用相同的方式,但它们似乎没有加载

另一个是我的子主题 CSS。它似乎加载到主页上,但在我的自定义页面上(到目前为止只做了一个)它没有加载。我在检查元素时检查了源选项卡,但它没有显示。

来自 functons.php 的外部脚本和 CSS 代码:

function external_load_scripts() {
    wp_register_script( 'popper', 'https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js' array('jquery'),'1.14.7', true );
    wp_enqueue_script( 'popper' );
    wp_register_script( 'bootstrap', 'https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js' array('jquery'),'4.3.1', true );
    wp_enqueue_script( 'bootstrap' );
    wp_register_script( 'datatables', 'https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js' array('jquery'),'1.10.12', true );
    wp_enqueue_script( 'datatables' );
    wp_register_script( 'chosen', 'https://cdnjs.cloudflare.com/ajax/libs/chosen/1.4.2/chosen.jquery.min.js' array('jquery'),'1.4.2', true );
    wp_enqueue_script( 'chosen' );
    wp_register_script( 'select', 'https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/js/select2.min.js' array('jquery'),'4.0.0', true );
    wp_enqueue_script( 'select' );
}

add_action('wp_enqueue_scripts', 'external_load_scripts');

function external_load_styles() {
    wp_register_style( 'chosencss', 'https://cdnjs.cloudflare.com/ajax/libs/chosen/1.4.2/chosen.min.css' );
    wp_enqueue_style( 'chosencss' );
    wp_register_style( 'selectcss', 'https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/css/select2.min.css' );
    wp_enqueue_style( 'selectcss' );
    wp_register_style( 'bootstrapcss', 'https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css' );
    wp_enqueue_style( 'bootstrapcss' );
    wp_register_style( 'allcss', 'https://use.fontawesome.com/releases/v5.0.13/css/all.css' );
    wp_enqueue_style( 'allcss' );
    wp_register_style( 'datatablescss', 'https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css' );
    wp_enqueue_style( 'datatablescss' );
}

add_action('wp_enqueue_scripts', 'external_load_styles');

在functions.php中注册子主题style.css

add_action( 'wp_enqueue_scripts', 'Eazy_Enqueue_styles' );
function Eazy_Enqueue_styles() {

    $parent_style = 'minimal-blocks-style'; 

    wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
    wp_enqueue_style( 'child-style',
        get_stylesheet_directory_uri() . '/style.css',
        array( $parent_style ),
        wp_get_theme()->get('Version')
    );
} 

如前所述,子 style.css 似乎适用于主页,但不适用于我使用自定义模板设计的自定义页面

解决这个问题的任何帮助都会很棒。提前致谢

最佳答案

还有一个我认为不是很好的解决方案

您尝试在主题文件夹的自定义页面中粘贴完整链接 css 和 js

例。 www.site.com/demo

文件:demo-page.php

关于javascript - 在 Wordpress 中排队外部 JS 和 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57707167/

相关文章:

javascript - Chartjs 雷达索引标签

javascript - 为什么没有记录任何内容?

javascript - 与 jQuery.noConflict() 冲突

javascript - 使用 selenium 检查 javascript 异常?

javascript - 在 sequelize.js 中使用构建方法时是否需要验证、清理或转义数据

javascript - CSS:在计时器上暂停动画

html - 单击 Outlook html 电子邮件中的 anchor 后颜色发生变化

html - 使用 css 和 html 对齐图像下的文本

javascript - JS检测屏幕宽度,运行不同的JS文件

javascript - Three.js Raycast 从鼠标位置关闭