[英]Javascript and Wordpress: Functions.php for a child theme to change a value on a JS file
In wordpress...I created a child theme. 在wordpress中...我创建了一个儿童主题。 Now I want to edit/change a value in main.js file.
现在,我要编辑/更改main.js文件中的值。 This file is part of the parent theme.
该文件是父主题的一部分。
As far as my research goes, I need to copy the file main.js into the child theme, folder js/main.js, and make the change there. 就我的研究而言,我需要将文件main.js复制到子主题文件夹js / main.js中,然后在其中进行更改。 Then, I need to add a file "functions.php" with code that deregister's the original main.js file in the parent theme, and redirect it to my main.js in the child theme's js folder.
然后,我需要添加一个文件“ functions.php”,其中包含取消注册父主题中原始main.js文件的代码,并将其重定向到子主题js文件夹中的main.js。 correct?
正确?
Every website I found online explaining this situation, was showing a very short description of the code for the php to deregister/dequeue and then register/enqueue the new file. 我在网上找到的每个网站都在解释这种情况,其中显示了一个简短的代码描述,供php注销/出队,然后注册/入队新文件。 Could anyone please write down the simplest functions.php file I need in order to have this done?
任何人都可以写下我要做的最简单的functions.php文件吗?
From the parent functions.php 从父functions.php
wp_register_script('main', JS_URI . '/main.js', 'jquery', false, true);
wp_register_script('main',JS_URI。'/ main.js','jquery',false,true);
wp_enqueue_script('main');
wp_enqueue_script( '主');
From js/main.js 从js / main.js
I'm only looking to change "play: 10000" for "play:1000 我只想将“播放:10000”更改为“播放:1000”
$(function() {
$('#slides').superslides({
animation: "fade",
play: 10000,
slide_easing: 'easeInOutCubic',
slide_speed: 800,
pagination: true,
hashchange: false,
scrollable: true
}); });
Thank you in advance! 先感谢您!
Try this in your functions.php file: 在您的functions.php文件中尝试以下操作:
<?php
wp_dequeue_script('main');
wp_deregister_script('main');
wp_register_script('main', YOUR_CHILD_THEME_JS_URI . '/main.js', 'jquery', false, true);
wp_enqueue_script('main');
Make sure to change YOUR_CHILD_THEME_JS_URI
to your child theme's JS path. 确保将
YOUR_CHILD_THEME_JS_URI
更改为您的子主题的JS路径。
You can use get_stylesheet_directory()
to get the path to your child theme folder since get_template_directory()
would return the path to the parent theme, and not your child theme. 您可以使用
get_stylesheet_directory()
获取子主题文件夹的路径,因为get_template_directory()
将返回父主题而不是子主题的路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.