[英]Do I need to create or override custom.js on a Wordpress Child theme?
So, I've created a child theme from the University Wordpress.org theme. 因此,我从大学Wordpress.org主题创建了一个子主题。 Created a new style.css file (which references the parent theme) and have a functions.php that looks like this: 创建了一个新的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' );
}
So, that loads great. 所以,这很棒。 Except the whole reason for me creating a child theme was so that I could modify 'Camera.js' - which is included in the parent's js file. 除了我创建子主题的全部原因是为了修改“ Camera.js”(包含在父级js文件中)。
The camera.js file includes the following line.... camera.js文件包括以下行...。
fx : 'random', //'random','simpleFade', 'curtainTopLeft', 'curtainTopRight', 'curtainBottomLeft', 'curtainBottomRight', 'curtainSliceLeft', 'curtainSliceRight', 'blindCurtainTopLeft',
with a whole load of other effects you can choose to apply by putting a new effect name in place of the first random
. 加上其他效果的全部负载,您可以选择应用新的效果名称代替第一个random
。
All I really want to do is have my child theme have just one of these effects applied without playing with the original Camera.js. 我真正想做的就是让我的孩子主题只应用其中一种效果,而不用玩原始的Camera.js。
The most obvious way I can think of doing this is duplicating the Camera.js file into my Child Theme folder and modifying it in there. 我想到的最明显的方法是将Camera.js文件复制到我的Child Theme文件夹中,然后在其中进行修改。 Would that work? 那行得通吗?
Thanks for any help! 谢谢你的帮助! Sorry if this has been asked elsewhere, I'm not entirely sure what I'm looking for to answer my question. 抱歉,如果在其他地方提出过此要求,我不确定要寻找什么来回答我的问题。
You cant over ride js files functionality so what you need to do is dequeue the original from your child theme and enqueue one from your child theme: 您无法超越ride js文件的功能,因此您需要做的是将原始主题从子主题中取出,并从子主题中取出一个:
eg dequeue script (you need to put in the handle the script was enqueued from) 例如出队脚本(您需要放入脚本入队的句柄)
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);
Note the above assumes the js file was enqueued in the standard way. 请注意,以上假设js文件已以标准方式入队。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.