【发布时间】:2014-08-17 07:53:33
【问题描述】:
我的父主题在 \includes\js\custom.js 中有一个脚本,我正试图从我的子主题中覆盖它。我可以从我的父主题中看到它是使用此代码排队的:(我已经修剪了一些不相关的 wp_enqueue_script() 调用行。)
function my_deregister_scripts() {
wp_deregister_script( 'jquery' );
wp_enqueue_script('jquery', get_template_directory_uri().'/includes/js/jquery.min.js', false, '1.6.4');
wp_enqueue_script('jquery-custom', get_template_directory_uri().'/includes/js/custom.js', false, '1.0');
if ( is_singular() && get_option('thread_comments') ) wp_enqueue_script( 'comment-reply' );
}
起初,我想我可以像这样简单地将一些代码添加到我自己的子functions.php中:
function custom_script_fix()
{
wp_dequeue_script( 'jquery-custom' );
wp_enqueue_script( 'child-jquery-custom', get_stylesheet_directory_uri() .'/includes/js/custom.js', false, '1.0');
}
add_action( 'wp_enqueue_scripts', 'custom_script_fix' );
但后来我在法典中读到,如今,子functions.php 在父functions.php 之前立即运行。这意味着我正在使将在父functions.php中再次入队的东西出队。这导致我的脚本首先被加载,然后是父脚本:
那么,在不以任何方式修改父主题的情况下,我将如何做到这一点?
【问题讨论】:
-
您可以尝试指定加载优先级吗? wordpress.stackexchange.com/questions/91961/…
-
我想通了,谢谢 ;)
标签: javascript php wordpress themes customization