如何添加符合WordPress插件的Java脚本? 时间:2020-03-05 作者:Nur Islam 我想在WordPress插件的Javascript中添加延迟,如何添加?/* Init AddToAny when an AddToAny WordPress Widget is selectively refreshed for customizer preview. */ jQuery( function() { // Short-circuit selective refresh events if not in customizer preview or pre-4.5. if ( \'undefined\' === typeof wp || ! wp.customize || ! wp.customize.selectiveRefresh ) { return; } function addtoany_init() { if ( window.a2a ) { a2a.init_all( \'page\' ); } } // Init AddToAny when a partial is rendered. wp.customize.selectiveRefresh.bind( \'partial-content-rendered\', function( placement ) { if ( placement.container ) { addtoany_init(); } } ); } ); 1 个回复 SO网友:sleepingpanda 有一个过滤器:script_loader_tag. 您可以使用它来查找正确的脚本:add_filter( \'script_loader_tag\', function ( $tag, $handle ) { if ( \'yourjsfilename.js\' !== $handle ) return $tag; return str_replace( \' src\', \' defer="defer" src\', $tag ); }, 10, 2 ); 如果有,请告诉我。 文章导航