js错误的快捷码无效。页面链接https://staging.sugrihini.com/test/ 使用
这[circleaudio src="/wp-content/uploads/2019/10/piano.mp3"]
定位错误
Uncaught TypeError: $ is not a function
at main.js?ver=0.0.3:1
===================插件代码===========
add_action(\'wp_enqueue_scripts\',\'circleaudioplayer_assets\');
function circleaudioplayer_assets(){
wp_enqueue_style( \'bar\', plugins_url( \'/progres-bar.css\' , __FILE__ ));
wp_enqueue_script( \'player\', plugins_url( \'/player.js\' , __FILE__ ),array("jquery"),\'0.0.1\',true);
wp_enqueue_script( \'main\', plugins_url( \'/main.js\' , __FILE__ ),array("jquery","player"),\'0.0.3\',true);
}
function circleaudioplayer( $atts ) {
$a = shortcode_atts( array(
\'src\' => \'\'
), $atts );
return \'<div class="mediPlayer">
<audio class="listen" preload="none" data-size="250" src="\' . $a[\'src\'] . \'"></audio></div></div>\';
}
add_shortcode( \'circleaudio\', \'circleaudioplayer\' );
最合适的回答,由SO网友:userone2 整理而成
您可以避免声明播放器是javascript文件的依赖项,问题是无法识别Jquery。更改此行:
wp_enqueue_script( \'main\', plugins_url( \'/main.js\' , __FILE__ ),array("jquery","player"),\'0.0.3\',true);
对此:
wp_enqueue_script( \'main\', plugins_url( \'/main.js\' , __FILE__ ), ["jquery"] );
还要避免将脚本排入页脚。