[英]How do I implement custom JS into my wordpress theme (Understrap)?
[英]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.