簡體   English   中英

我是否需要在Wordpress Child主題上創建或覆蓋custom.js?

[英]Do I need to create or override custom.js on a Wordpress Child theme?

因此,我從大學Wordpress.org主題創建了一個子主題。 創建了一個新的style.css文件(該文件引用了父主題),並具有一個如下所示的functions.php:

<?php
 add_action( 'wp_enqueue_scripts', 'enqueue_child_theme_styles',      PHP_INT_MAX);
function enqueue_child_theme_styles() {
wp_enqueue_style( 'university', get_template_directory_uri().'/style.css' );
wp_enqueue_style( 'university', get_template_directory_uri() . '/custom.css'      );
 }

所以,這很棒。 除了我創建子主題的全部原因是為了修改“ Camera.js”(包含在父級js文件中)。

camera.js文件包括以下行...。

fx : 'random', //'random','simpleFade', 'curtainTopLeft', 'curtainTopRight', 'curtainBottomLeft', 'curtainBottomRight', 'curtainSliceLeft', 'curtainSliceRight', 'blindCurtainTopLeft',

加上其他效果的全部負載,您可以選擇應用新的效果名稱代替第一個random

我真正想做的就是讓我的孩子主題只應用其中一種效果,而不用玩原始的Camera.js。

我想到的最明顯的方法是將Camera.js文件復制到我的Child Theme文件夾中,然后在其中進行修改。 那行得通嗎?

謝謝你的幫助! 抱歉,如果在其他地方提出過此要求,我不確定要尋找什么來回答我的問題。

您無法超越ride js文件的功能,因此您需要做的是將原始主題從子主題中取出,並從子主題中取出一個:

例如出隊腳本(您需要放入腳本入隊的句柄)

function remove_script(){
    wp_dequeue_script('script_handle_used_to_enqueue');
    wp_enqueue_script( 'newhandle', get_stylesheet_directory_uri() . '/js/Camera.js');
}
add_action('wp_print_scripts', 'remove_script', 100);

請注意,以上假設js文件已以標准方式入隊。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM