简体   繁体   English

Javascript和Wordpress:子主题的Functions.php,用于更改JS文件上的值

[英]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.

相关问题 使用functions.php文件在wordpress主题中包含javascript文件 - include javascript files in wordpress theme using functions.php file 如何在Wordpress子主题functions.php中正确排队retina.js? - How do I enqueue retina.js in a Wordpress child theme functions.php properly? 如何在WordPress子主题中的functions.php上添加多个脚本? - How to add multiple script on functions.php in wordpress child theme? WordPress-functions.php将不会注册我的JavaScript文件 - WordPress - functions.php will not register my JavaScript file WordPress 在函数中使用 JavaScript 将 CSS 文件排队。ZE1BFD762321E409CEEZBAC01 - WordPress enqueuing a CSS file using JavaScript inside Functions.php Javascript文件在Wordpress中无法正常运行,而在Function.php中却无法正确入队 - Javascript File Not Functioning in Wordpress w/ Proper Enqueueing in Functions.php 通过子主题函数向PHP插件自定义帖子类型添加选项 - Add options to a Wordpress plugin Custom Post Type via child theme functions.php functions.php 文件未在 js 文件夹中运行我的 JavaScript - functions.php file not running my JavaScript in js folder 在Wordpress中将自定义javascript添加到functions.php - Adding custom javascript to functions.php in wordpress 将javascript添加到wordpress functions.php - Adding javascript to wordpress functions.php
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM