![](/img/trans.png)
[英]include javascript files in wordpress theme using functions.php file
[英]Javascript and Wordpress: Functions.php for a child theme to change a value on a JS file
在wordpress中...我創建了一個兒童主題。 現在,我要編輯/更改main.js文件中的值。 該文件是父主題的一部分。
就我的研究而言,我需要將文件main.js復制到子主題文件夾js / main.js中,然后在其中進行更改。 然后,我需要添加一個文件“ functions.php”,其中包含取消注冊父主題中原始main.js文件的代碼,並將其重定向到子主題js文件夾中的main.js。 正確?
我在網上找到的每個網站都在解釋這種情況,其中顯示了一個簡短的代碼描述,供php注銷/出隊,然后注冊/入隊新文件。 任何人都可以寫下我要做的最簡單的functions.php文件嗎?
從父functions.php
wp_register_script('main',JS_URI。'/ main.js','jquery',false,true);
wp_enqueue_script( '主');
從js / main.js
我只想將“播放:10000”更改為“播放:1000”
$(function() {
$('#slides').superslides({
animation: "fade",
play: 10000,
slide_easing: 'easeInOutCubic',
slide_speed: 800,
pagination: true,
hashchange: false,
scrollable: true
}); });
先感謝您!
在您的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');
確保將YOUR_CHILD_THEME_JS_URI
更改為您的子主題的JS路徑。
您可以使用get_stylesheet_directory()
獲取子主題文件夾的路徑,因為get_template_directory()
將返回父主題而不是子主題的路徑。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.