我建立了一个儿童主题Divi Theme 用于Buddypress. 到目前为止还不错,除了注释按钮上的脚本冲突。
主题加载javascript(js/custom.js 在2642:2662),具有以下功能:
    $( \'a[href*=#]:not([href=#])\' ).click( function() {
        if ( $(this).closest( \'.woocommerce-tabs\' ).length && $(this).closest( \'.tabs\' ).length ) {
            return false;
        }
        if ( location.pathname.replace( /^\\//,\'\' ) == this.pathname.replace( /^\\//,\'\' ) && location.hostname == this.hostname ) {
            var target = $( this.hash );
            target = target.length ? target : $( \'[name=\' + this.hash.slice(1) +\']\' );
            if ( target.length ) {
                et_pb_smooth_scroll( target, false, 800 );
                if ( ! $( \'#main-header\' ).hasClass( \'et-fixed-header\' ) && $( \'body\' ).hasClass( \'et_fixed_nav\' ) && $( window ).width() > 980 ) {
                        setTimeout(function(){
                        et_pb_smooth_scroll( target, false, 200);
                    }, 500 );
                }
                return false;
            }
        }
    });
 此事件的目标是Buddypress用于评论的同一个按钮,防止在单击时加载AJAX表单。

我不想编辑父主题(custom.js)。我如何防止这种冲突?是否有解决方法,可能来自functions.php?
UPDATE
使用
wp_dequeue_script 要稍后加载该脚本,无法运行。在函数中使用此代码时。php
function de_script() {
    wp_dequeue_script( \'divi-custom-script\' );
}
add_action( \'wp_print_scripts\', \'de_script\', 100 );
 然后根本没有加载完整的脚本(custom.js)。
 
                    最合适的回答,由SO网友:Giulio Bonanome 整理而成
                    首先,为了解决javascript冲突,我设置了一个tl_custom.js 在我的主题下js/ 文件夹,具有以下代码
jQuery(document).ready(function($) {
    //  Remove handler set by themes/Divi/js/custom.js at line 2642
    $( \'a[href*=#]:not([href=#])\' ).off();
});
 然后,在中添加带有以下代码的脚本
functions.phpfunction tl_custom_scripts() {
    if ( ! is_admin() ) {
        $scriptsrc = get_stylesheet_directory_uri() . \'/js/\';
        wp_register_script( \'tl_custom\', $scriptsrc . \'tl_custom.js\', \'\', \'\', true );
        wp_enqueue_script( \'tl_custom\' );
    }
}
add_action( \'wp_enqueue_scripts\', \'tl_custom_scripts\', 20 );
 主要问题是父主题注册
custom.js 在页脚中,所以我必须设置
wp_register_script 最后一个参数到
true 然后设置
add_action 优先级为20。