【发布时间】:2013-12-10 06:58:26
【问题描述】:
所以我刚刚发现了 Wordpress 子主题的世界,这对我来说特别有希望,因为我编辑的不仅仅是 CSS(一些 php 和 js 文件)。我知道我的子主题可以正常工作,因为我复制了在 404.php 页面上,对内容进行了一些更改并尝试强制 404,它给了我新的子主题的 404 页面——所以到目前为止我们知道它是有效的。
现在我在我的子主题的functions.php 文件中对retina.js 进行排队时遇到问题。我的问题是我似乎无法弄清楚如何更改代码以使其指向 child 主题中的视网膜.js 文件,而不是 parent。我知道至少 enqueue 有效,因为它仅在我的子主题中的 functions.php 中,而不在我的父主题中(否则它无论如何都不起作用。)我已经通过删除视网膜来测试它。 js 文件从父主题,并注意到它显然停止工作,然后重新上传文件并获取视网膜图像。
我将在下面发布代码,如果能帮助我让它指向子主题文件,而不是父文件,我将不胜感激。提前致谢!
<?php
#-----------------------------------------------------------------#
# Enqueue retina.js
#-----------------------------------------------------------------#
add_action( 'wp_enqueue_scripts', 'retina_support_enqueue_scripts' );
/**
* Enqueueing retina.js
*
* This function is attached to the 'wp_enqueue_scripts' action hook.
*/
function retina_support_enqueue_scripts() {
wp_enqueue_script( 'retina_js', get_template_directory_uri() . '/js/retina.js', '', '', true );
}
?>
编辑:@Veelen 在下面回答了我的问题,对于那些好奇的人,这就是我的子主题中的 functions.php 最终如何修复:
<?php
#-----------------------------------------------------------------#
# Register/Enqueue retina.js
#-----------------------------------------------------------------#
add_action( 'wp_enqueue_scripts', 'retina_support_enqueue_scripts' );
/**
* Enqueueing retina.js
*
* This function is attached to the 'wp_enqueue_scripts' action hook.
*/
function retina_support_enqueue_scripts() {
wp_enqueue_script( 'retina_js', get_stylesheet_directory_uri() . '/js/retina.js', '', '', true );
}
?>
【问题讨论】:
标签: javascript php jquery wordpress retina.js