我已经构建了一个Divi主题的子主题,以便与巴迪出版社一起使用。到目前为止还不错,除了注释按钮上的脚本冲突。
主题加载具有以下功能的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
更新
稍后使用wp_dequeue_script加载该脚本,但不起作用。在functions.php中使用此代码时
function de_script() {
wp_dequeue_script( 'divi-custom-script' );
}
add_action( 'wp_print_scripts', 'de_script', 100 );
然后完全没有加载完整的脚本(custom.js)。
发布于 2015-03-02 02:14:38
首先,为了解决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.php
中添加了下面的代码
function 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
,因此我不得不将脚本的最后一个参数设置为true
,然后将动作优先级设置为20。
发布于 2016-05-16 22:51:32
这个答案现在可能有点晚了,但我目前正在从事一个继承的项目,我继续工作。我发现他们在更新的Wordpress上使用了Divi主题,它触发了上面所有的错误。
我检查了源错误,发现这个选择器不正确:
$( 'a[href*=#]:not([href=#])' )
我通过在不影响任何功能的情况下将其更改为它来修正这个问题:
$( 'a[href*=\\#]:not([href=\\#])' )
它还在以下方面开展工作:
$( 'a[href*="#"]:not([href="#"])' )
问题已经解决,该代码块的功能仍在工作。
https://stackoverflow.com/questions/28782415
复制相似问题