css - 无法将新脚本加入 parent 主题

标签 css wordpress lightbox2

我正在尝试将新脚本和一个 css 文件添加到我 child 在 wordpress 上的主题,但出现以下错误。

GET https://linton59.co.uk/wp-content/themes/simpleshift/css/lightbox.css?ver=4.3.0 net::ERR_ABORTED
(index):280 GET https://linton59.co.uk/wp-content/themes/simpleshift/js/lightbox-plus-jquery.js?ver=3.3.0 net::ERR_ABORTED
(index):279 GET https://linton59.co.uk/wp-content/themes/simpleshift/js/lightbox.js?ver=3.3.0 net::ERR_ABORTED
(index):68 GET https://linton59.co.uk/wp-content/themes/simpleshift/css/lightbox.css?ver=4.3.0 net::ERR_ABORTED

以下是我正在使用的 functions.php。

<?php
// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) exit;

// BEGIN ENQUEUE PARENT ACTION
// AUTO GENERATED - Do not modify or remove comment markers above or below:

if ( !function_exists( 'chld_thm_cfg_parent_css' ) ):
    function chld_thm_cfg_parent_css() {
        wp_enqueue_style( 'chld_thm_cfg_parent', trailingslashit( get_template_directory_uri() ) . 'style.css', array( 'bootstrap','font-awesome' ) );
    }
endif;
add_action( 'wp_enqueue_scripts', 'chld_thm_cfg_parent_css', 10 );

// END ENQUEUE PARENT ACTION

add_action( 'wp_enqueue_scripts', 'theme_name_scripts', 20 );
function theme_name_scripts() {
    wp_dequeue_script( 'simpleshift_public' );
    wp_enqueue_script( 'myscript', get_stylesheet_directory_uri() .'/js/public.js', array( 'jquery' ), '1.0', true);
}

add_action( 'wp_enqueue_scripts', 'theme_light', 30 );
function theme_light() {
    wp_dequeue_script( 'simpleshift_public' );
      wp_enqueue_style( 'lightbox', get_template_directory_uri() . '/css/lightbox.css', array(), '4.3.0' );
wp_enqueue_script( 'lightbox2', get_template_directory_uri() . '/js/lightbox.js', array( 'jquery' ), '3.3.0', true );
wp_enqueue_script( 'lightbox3', get_template_directory_uri() . '/js/lightbox-plus-jquery.js', array( 'jquery' ), '3.3.0', true );




}

我 child 的主题有一个 css 文件夹和一个 js 文件夹,里面有相关文件。 最后一个 Action 是唯一不起作用的部分。

最佳答案

get_template_directory_uri() 将始终返回当前父主题的 URI。

要改为获取子主题 URI,您需要使用 get_stylesheet_directory_uri()。

关于css - 无法将新脚本加入 parent 主题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48212071/

相关文章:

jQuery UI Datepicker - 如何始终将其显示在顶部 : 240px?

javascript - JQuery - 向下滚动时隐藏,向上滚动时部分显示,在顶部时完全显示

css - 二级下拉菜单在其他页面上保持事件状态

php - WooCommerce:从数组中的产品中获取评论并按星级对它们进行排序

javascript - 灯箱正在下载图片而不是显示图片

可以查看 PDF 的 Javascript 和 CSS Lightbox

html - 气泡(聊天)框 css3

wordpress - woocommerce 上的多种货币,可根据位置自动切换

mysql - 编写 mysql 查询的想法

javascript - MVC下如何使用Lightbox